[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 25 | #include "base/optional.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 30 | #include "base/strings/stringprintf.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 32 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 33 | #include "base/test/scoped_feature_list.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 34 | #include "base/test/simple_test_clock.h" |
| 35 | #include "base/test/simple_test_tick_clock.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 36 | #include "base/test/task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 37 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 38 | #include "base/threading/thread_task_runner_handle.h" |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 39 | #include "build/build_config.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 40 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 41 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 42 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 43 | #include "net/base/elements_upload_data_stream.h" |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 44 | #include "net/base/features.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 45 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 46 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 47 | #include "net/base/load_timing_info.h" |
| 48 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 49 | #include "net/base/net_errors.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 50 | #include "net/base/privacy_mode.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 51 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 52 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 53 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 54 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 55 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 56 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 57 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 58 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 59 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 60 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 61 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 62 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 63 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 64 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 65 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 66 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 67 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 68 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 69 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 70 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 71 | #include "net/http/http_response_info.h" |
Matt Menke | 60916074 | 2019-08-02 18:47:26 | [diff] [blame] | 72 | #include "net/http/http_server_properties.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 73 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 74 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 75 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 76 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 77 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 78 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 79 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 80 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 81 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 82 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 83 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 84 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 85 | #include "net/proxy_resolution/proxy_resolver.h" |
| 86 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 87 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 88 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 89 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 90 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 91 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 92 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 93 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 94 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 95 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 96 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 97 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 98 | #include "net/spdy/spdy_session.h" |
| 99 | #include "net/spdy/spdy_session_pool.h" |
| 100 | #include "net/spdy/spdy_test_util_common.h" |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 101 | #include "net/ssl/client_cert_identity_test_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 102 | #include "net/ssl/ssl_cert_request_info.h" |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 103 | #include "net/ssl/ssl_config.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 104 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 105 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 106 | #include "net/ssl/ssl_private_key.h" |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 107 | #include "net/ssl/test_ssl_config_service.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 108 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 109 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 110 | #include "net/test/test_data_directory.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 111 | #include "net/test/test_with_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 112 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 113 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 114 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 115 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 116 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 117 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 118 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 119 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 120 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 121 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 122 | #if defined(NTLM_PORTABLE) |
| 123 | #include "base/base64.h" |
| 124 | #include "net/ntlm/ntlm_test_data.h" |
| 125 | #endif |
| 126 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 127 | #if BUILDFLAG(ENABLE_REPORTING) |
| 128 | #include "net/network_error_logging/network_error_logging_service.h" |
| 129 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 130 | #include "net/reporting/reporting_cache.h" |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 131 | #include "net/reporting/reporting_endpoint.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 132 | #include "net/reporting/reporting_header_parser.h" |
| 133 | #include "net/reporting/reporting_service.h" |
| 134 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 135 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 136 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 137 | using net::test::IsError; |
| 138 | using net::test::IsOk; |
| 139 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 140 | using base::ASCIIToUTF16; |
| 141 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 142 | using testing::AnyOf; |
| 143 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 144 | //----------------------------------------------------------------------------- |
| 145 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 146 | namespace net { |
| 147 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 148 | namespace { |
| 149 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 150 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 151 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 152 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 153 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 154 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 155 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 156 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 157 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 158 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 159 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 160 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 161 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 162 | const char kAlternativeServiceHttpHeader[] = |
| 163 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 164 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 165 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 166 | return session |
| 167 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 168 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 169 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 170 | } |
| 171 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 172 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 173 | return session |
| 174 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 175 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 176 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 179 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 180 | // a JSONified list of headers as a single string. Uses single quotes instead |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 181 | // of double quotes for easier comparison. |
| 182 | std::string GetHeaders(const base::Value& params) { |
| 183 | if (!params.is_dict()) |
| 184 | return ""; |
| 185 | const base::Value* header_list = params.FindListKey("headers"); |
| 186 | if (!header_list) |
| 187 | return ""; |
| 188 | std::string headers; |
| 189 | base::JSONWriter::Write(*header_list, &headers); |
| 190 | base::ReplaceChars(headers, "\"", "'", &headers); |
| 191 | return headers; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 195 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 196 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 198 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 199 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 201 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 202 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 203 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 204 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 205 | |
| 206 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 207 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 208 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 209 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 210 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 211 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 212 | } |
| 213 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 215 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 216 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 217 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 219 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | |
| 221 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 222 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 223 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 224 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 225 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 227 | load_timing_info.send_start); |
| 228 | |
| 229 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 230 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 231 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 232 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 233 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 234 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 238 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 239 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 240 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 241 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 242 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 243 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | |
| 245 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 246 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 247 | load_timing_info.proxy_resolve_end); |
| 248 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 249 | load_timing_info.send_start); |
| 250 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 251 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 252 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 253 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 254 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 255 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 259 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 260 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | int connect_timing_flags) { |
| 262 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 263 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | |
| 265 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 266 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 267 | load_timing_info.proxy_resolve_end); |
| 268 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 269 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 270 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 271 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 273 | load_timing_info.send_start); |
| 274 | |
| 275 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 276 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 277 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 278 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 279 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 280 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 281 | } |
| 282 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 283 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 284 | // result to return. |
| 285 | class CapturingProxyResolver : public ProxyResolver { |
| 286 | public: |
| 287 | CapturingProxyResolver() |
| 288 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 289 | ~CapturingProxyResolver() override = default; |
| 290 | |
| 291 | int GetProxyForURL(const GURL& url, |
| 292 | ProxyInfo* results, |
| 293 | CompletionOnceCallback callback, |
| 294 | std::unique_ptr<Request>* request, |
| 295 | const NetLogWithSource& net_log) override { |
| 296 | results->UseProxyServer(proxy_server_); |
| 297 | resolved_.push_back(url); |
| 298 | return OK; |
| 299 | } |
| 300 | |
| 301 | // Sets whether the resolver should use direct connections, instead of a |
| 302 | // proxy. |
| 303 | void set_proxy_server(ProxyServer proxy_server) { |
| 304 | proxy_server_ = proxy_server; |
| 305 | } |
| 306 | |
| 307 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 308 | |
| 309 | private: |
| 310 | std::vector<GURL> resolved_; |
| 311 | |
| 312 | ProxyServer proxy_server_; |
| 313 | |
| 314 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 315 | }; |
| 316 | |
| 317 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 318 | public: |
| 319 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 320 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 321 | |
| 322 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 323 | std::unique_ptr<ProxyResolver>* resolver, |
| 324 | CompletionOnceCallback callback, |
| 325 | std::unique_ptr<Request>* request) override { |
| 326 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 327 | return OK; |
| 328 | } |
| 329 | |
| 330 | private: |
| 331 | ProxyResolver* resolver_; |
| 332 | }; |
| 333 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 334 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 335 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 336 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 337 | } |
| 338 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 339 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 340 | public: |
| 341 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 342 | |
| 343 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 344 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 345 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 346 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 347 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 348 | return ERR_PAC_SCRIPT_FAILED; |
| 349 | } |
| 350 | }; |
| 351 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 352 | } // namespace |
| 353 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 354 | class HttpNetworkTransactionTest : public PlatformTest, |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 355 | public WithTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 356 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 357 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 358 | // Important to restore the per-pool limit first, since the pool limit must |
| 359 | // always be greater than group limit, and the tests reduce both limits. |
| 360 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 361 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 362 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 363 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 364 | } |
| 365 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 366 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 367 | HttpNetworkTransactionTest() |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 368 | : WithTaskEnvironment(base::test::TaskEnvironment::TimeSource::MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 369 | dummy_connect_job_params_( |
| 370 | nullptr /* client_socket_factory */, |
| 371 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 372 | nullptr /* http_auth_cache */, |
| 373 | nullptr /* http_auth_handler_factory */, |
| 374 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 375 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 376 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 377 | nullptr /* proxy_delegate */, |
| 378 | nullptr /* http_user_agent_settings */, |
David Benjamin | 24725be | 2019-07-24 20:57:18 | [diff] [blame] | 379 | nullptr /* ssl_client_context */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 380 | nullptr /* socket_performance_watcher_factory */, |
| 381 | nullptr /* network_quality_estimator */, |
| 382 | nullptr /* net_log */, |
| 383 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 384 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 385 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 386 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 387 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 388 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 389 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 390 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 391 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 392 | struct SimpleGetHelperResult { |
| 393 | int rv; |
| 394 | std::string status_line; |
| 395 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 396 | int64_t total_received_bytes; |
| 397 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 398 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 399 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 400 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 401 | }; |
| 402 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 403 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 404 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 405 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 406 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 407 | // before incrementing the counter does not return a null value. |
Matt Menke | 6dc0823 | 2019-10-03 18:00:28 | [diff] [blame] | 408 | FastForwardBy(base::TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 409 | } |
| 410 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 411 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 412 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 413 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 414 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 415 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 416 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 417 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 418 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 419 | } |
| 420 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 421 | void Check100ResponseTiming(bool use_spdy); |
| 422 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 423 | // Either |write_failure| specifies a write failure or |read_failure| |
| 424 | // specifies a read failure when using a reused socket. In either case, the |
| 425 | // failure should cause the network transaction to resend the request, and the |
| 426 | // other argument should be NULL. |
| 427 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 428 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 429 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 430 | // Either |write_failure| specifies a write failure or |read_failure| |
| 431 | // specifies a read failure when using a reused socket. In either case, the |
| 432 | // failure should cause the network transaction to resend the request, and the |
| 433 | // other argument should be NULL. |
| 434 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 435 | const MockRead* read_failure, |
| 436 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 437 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 438 | SimpleGetHelperResult SimpleGetHelperForData( |
| 439 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 440 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 442 | HttpRequestInfo request; |
| 443 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 444 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 445 | request.traffic_annotation = |
| 446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 447 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 448 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 449 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 453 | for (auto* provider : providers) { |
| 454 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 455 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 457 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 458 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 459 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 460 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 462 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 463 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 464 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 465 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 466 | |
| 467 | // Even in the failure cases that use this function, connections are always |
| 468 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 469 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 470 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 471 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 472 | if (out.rv != OK) |
| 473 | return out; |
| 474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 475 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 476 | // Can't use ASSERT_* inside helper functions like this, so |
| 477 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 478 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 479 | out.rv = ERR_UNEXPECTED; |
| 480 | return out; |
| 481 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 482 | out.status_line = response->headers->GetStatusLine(); |
| 483 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 484 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 485 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 486 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 487 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 488 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 489 | EXPECT_EQ(got_endpoint, |
| 490 | out.remote_endpoint_after_start.address().size() > 0); |
| 491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 492 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 493 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 494 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 495 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 496 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 497 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 498 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 499 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 500 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 501 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 502 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 503 | EXPECT_EQ("GET / HTTP/1.1\r\n", |
| 504 | GetStringValueFromParams(entries[pos], "line")); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 505 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 506 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 507 | GetHeaders(entries[pos].params)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 509 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 510 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 511 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 512 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 513 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 514 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 515 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 516 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 517 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 518 | MockWrite data_writes[] = { |
| 519 | MockWrite("GET / HTTP/1.1\r\n" |
| 520 | "Host: www.example.org\r\n" |
| 521 | "Connection: keep-alive\r\n\r\n"), |
| 522 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 523 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 524 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 525 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 526 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 527 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 528 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 529 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 530 | } |
| 531 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 532 | void AddSSLSocketData() { |
| 533 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 534 | ssl_.ssl_info.cert = |
| 535 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 536 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 537 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 538 | } |
| 539 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 540 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 541 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 542 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 543 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 544 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 545 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 546 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 547 | const CommonConnectJobParams dummy_connect_job_params_; |
| 548 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 549 | // These clocks are defined here, even though they're only used in the |
| 550 | // Reporting tests below, since they need to be destroyed after |
| 551 | // |session_deps_|. |
| 552 | base::SimpleTestClock clock_; |
| 553 | base::SimpleTestTickClock tick_clock_; |
| 554 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 555 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 556 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 557 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 558 | |
| 559 | // Original socket limits. Some tests set these. Safest to always restore |
| 560 | // them once each test has been run. |
| 561 | int old_max_group_sockets_; |
| 562 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 563 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 564 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 565 | namespace { |
| 566 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 567 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 568 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 569 | BeforeHeadersSentHandler() |
| 570 | : observed_before_headers_sent_with_proxy_(false), |
| 571 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 572 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 573 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 574 | HttpRequestHeaders* request_headers) { |
| 575 | observed_before_headers_sent_ = true; |
| 576 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 577 | !proxy_info.is_quic()) { |
| 578 | return; |
| 579 | } |
| 580 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 581 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 582 | } |
| 583 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 584 | bool observed_before_headers_sent_with_proxy() const { |
| 585 | return observed_before_headers_sent_with_proxy_; |
| 586 | } |
| 587 | |
| 588 | bool observed_before_headers_sent() const { |
| 589 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | std::string observed_proxy_server_uri() const { |
| 593 | return observed_proxy_server_uri_; |
| 594 | } |
| 595 | |
| 596 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | bool observed_before_headers_sent_with_proxy_; |
| 598 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 599 | std::string observed_proxy_server_uri_; |
| 600 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 601 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 602 | }; |
| 603 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 604 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 605 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 606 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 607 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 608 | const int sizeof_row = strlen(row); |
| 609 | const int num_rows = static_cast<int>( |
| 610 | ceil(static_cast<float>(size) / sizeof_row)); |
| 611 | const int sizeof_data = num_rows * sizeof_row; |
| 612 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 613 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 614 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 615 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 616 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 617 | } |
| 618 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 619 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 620 | uint64_t MockGetMSTime() { |
| 621 | // Tue, 23 May 2017 20:13:07 +0000 |
| 622 | return 131400439870000000; |
| 623 | } |
| 624 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 625 | // Alternative functions that eliminate randomness and dependency on the local |
| 626 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 627 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 628 | // This is set to 0xaa because the client challenge for testing in |
| 629 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 630 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 631 | } |
| 632 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 633 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 634 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 635 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 636 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 637 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 638 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 639 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 640 | explicit CaptureGroupIdTransportSocketPool( |
| 641 | const CommonConnectJobParams* common_connect_job_params) |
| 642 | : TransportClientSocketPool(0, |
| 643 | 0, |
| 644 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 645 | ProxyServer::Direct(), |
| 646 | false /* is_for_websockets */, |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 647 | common_connect_job_params) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 648 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 649 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 650 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 651 | } |
| 652 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 653 | bool socket_requested() const { return socket_requested_; } |
| 654 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 655 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 656 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 657 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 658 | const base::Optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 659 | RequestPriority priority, |
| 660 | const SocketTag& socket_tag, |
| 661 | ClientSocketPool::RespectLimits respect_limits, |
| 662 | ClientSocketHandle* handle, |
| 663 | CompletionOnceCallback callback, |
| 664 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 665 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 666 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 667 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 668 | return ERR_IO_PENDING; |
| 669 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 670 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 671 | ClientSocketHandle* handle, |
| 672 | bool cancel_connect_job) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 673 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 674 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 675 | int64_t generation) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 676 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 677 | void CloseIdleSocketsInGroup( |
| 678 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 680 | size_t IdleSocketCountInGroup( |
| 681 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 682 | return 0; |
| 683 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 684 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 685 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 686 | return LOAD_STATE_IDLE; |
| 687 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 688 | |
| 689 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 690 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 691 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 692 | }; |
| 693 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 694 | //----------------------------------------------------------------------------- |
| 695 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 696 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 697 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 698 | bool CheckBasicServerAuth( |
| 699 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 700 | if (!auth_challenge) |
| 701 | return false; |
| 702 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 703 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 704 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 705 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 706 | return true; |
| 707 | } |
| 708 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 709 | bool CheckBasicSecureServerAuth( |
| 710 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
| 711 | if (!auth_challenge) |
| 712 | return false; |
| 713 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 714 | EXPECT_EQ("https://www.example.org", auth_challenge->challenger.Serialize()); |
| 715 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 716 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 717 | return true; |
| 718 | } |
| 719 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 720 | bool CheckBasicProxyAuth( |
| 721 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 722 | if (!auth_challenge) |
| 723 | return false; |
| 724 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 725 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 726 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 727 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 728 | return true; |
| 729 | } |
| 730 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 731 | bool CheckBasicSecureProxyAuth( |
| 732 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 733 | if (!auth_challenge) |
| 734 | return false; |
| 735 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 736 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 737 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 738 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 739 | return true; |
| 740 | } |
| 741 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 742 | bool CheckDigestServerAuth( |
| 743 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 744 | if (!auth_challenge) |
| 745 | return false; |
| 746 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 747 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 748 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 749 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 750 | return true; |
| 751 | } |
| 752 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 753 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 754 | bool CheckNTLMServerAuth( |
| 755 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 756 | if (!auth_challenge) |
| 757 | return false; |
| 758 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 759 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 760 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 761 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 762 | return true; |
| 763 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 764 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 765 | bool CheckNTLMProxyAuth( |
| 766 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 767 | if (!auth_challenge) |
| 768 | return false; |
| 769 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 770 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 771 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 772 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 773 | return true; |
| 774 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 775 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 776 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 777 | } // namespace |
| 778 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 779 | // TODO(950069): Add testing for frame_origin in NetworkIsolationKey |
| 780 | // using kAppendInitiatingFrameOriginToNetworkIsolationKey. |
| 781 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 782 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | } |
| 786 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 787 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 788 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 789 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 790 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 792 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 793 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 794 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 796 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 797 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 798 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 799 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 800 | |
| 801 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 805 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 806 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 807 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 808 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 810 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 811 | EXPECT_THAT(out.rv, IsOk()); |
| 812 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 813 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 814 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 815 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | } |
| 817 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 818 | // Response with no status line, and a weird port. Should fail by default. |
| 819 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 820 | MockRead data_reads[] = { |
| 821 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 822 | }; |
| 823 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 824 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 825 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 826 | |
| 827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 828 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 829 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 830 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 831 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 832 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 833 | request.method = "GET"; |
| 834 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 835 | request.traffic_annotation = |
| 836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 837 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 838 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 839 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 840 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 841 | } |
| 842 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 843 | // Tests that request info can be destroyed after the headers phase is complete. |
| 844 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 846 | auto trans = |
| 847 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 848 | |
| 849 | MockRead data_reads[] = { |
| 850 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 851 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 852 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 853 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 855 | |
| 856 | TestCompletionCallback callback; |
| 857 | |
| 858 | { |
| 859 | auto request = std::make_unique<HttpRequestInfo>(); |
| 860 | request->method = "GET"; |
| 861 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 862 | request->traffic_annotation = |
| 863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 864 | |
| 865 | int rv = |
| 866 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 867 | |
| 868 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 869 | } // Let request info be destroyed. |
| 870 | |
| 871 | trans.reset(); |
| 872 | } |
| 873 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 874 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 875 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 876 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 877 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 878 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 879 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 880 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 881 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 882 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 883 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 884 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 885 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 889 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 890 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 891 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 893 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 894 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 895 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 896 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 897 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 898 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 899 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 903 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 904 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 905 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 906 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 907 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 908 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 909 | EXPECT_THAT(out.rv, IsOk()); |
| 910 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 911 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 912 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 913 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 917 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 918 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 919 | MockRead("\n"), |
| 920 | MockRead("\n"), |
| 921 | MockRead("Q"), |
| 922 | MockRead("J"), |
| 923 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 926 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 927 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 928 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 929 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 930 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 931 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 935 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 937 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 938 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 940 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 941 | EXPECT_THAT(out.rv, IsOk()); |
| 942 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 943 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 944 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 945 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 946 | } |
| 947 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 948 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 949 | // persistent connection. The response should still terminate since a 204 |
| 950 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 951 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 952 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 953 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 954 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 955 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 956 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 957 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 958 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 959 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 960 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 961 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 962 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 963 | int64_t response_size = reads_size - strlen(junk); |
| 964 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 965 | } |
| 966 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 967 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 968 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 969 | std::string final_chunk = "0\r\n\r\n"; |
| 970 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 971 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 972 | MockRead data_reads[] = { |
| 973 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 974 | MockRead("5\r\nHello\r\n"), |
| 975 | MockRead("1\r\n"), |
| 976 | MockRead(" \r\n"), |
| 977 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 978 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 981 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 982 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 983 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 984 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 985 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 986 | int64_t response_size = reads_size - extra_data.size(); |
| 987 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 988 | } |
| 989 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 990 | // Next tests deal with http://crbug.com/56344. |
| 991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 992 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 993 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 994 | MockRead data_reads[] = { |
| 995 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 996 | MockRead("Content-Length: 10\r\n"), |
| 997 | MockRead("Content-Length: 5\r\n\r\n"), |
| 998 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 999 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1000 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1001 | } |
| 1002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1003 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1004 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1005 | MockRead data_reads[] = { |
| 1006 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1007 | MockRead("Content-Length: 5\r\n"), |
| 1008 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1009 | MockRead("Hello"), |
| 1010 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1011 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1012 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1013 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1014 | EXPECT_EQ("Hello", out.response_data); |
| 1015 | } |
| 1016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1017 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1018 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1019 | // More than 2 dupes. |
| 1020 | { |
| 1021 | MockRead data_reads[] = { |
| 1022 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1023 | MockRead("Content-Length: 5\r\n"), |
| 1024 | MockRead("Content-Length: 5\r\n"), |
| 1025 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1026 | MockRead("Hello"), |
| 1027 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1028 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1029 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1030 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1031 | EXPECT_EQ("Hello", out.response_data); |
| 1032 | } |
| 1033 | // HTTP/1.0 |
| 1034 | { |
| 1035 | MockRead data_reads[] = { |
| 1036 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1037 | MockRead("Content-Length: 5\r\n"), |
| 1038 | MockRead("Content-Length: 5\r\n"), |
| 1039 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1040 | MockRead("Hello"), |
| 1041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1042 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1043 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1044 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1045 | EXPECT_EQ("Hello", out.response_data); |
| 1046 | } |
| 1047 | // 2 dupes and one mismatched. |
| 1048 | { |
| 1049 | MockRead data_reads[] = { |
| 1050 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1051 | MockRead("Content-Length: 10\r\n"), |
| 1052 | MockRead("Content-Length: 10\r\n"), |
| 1053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1054 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1055 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1056 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1060 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1061 | MultipleContentLengthHeadersTransferEncoding) { |
| 1062 | MockRead data_reads[] = { |
| 1063 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1064 | MockRead("Content-Length: 666\r\n"), |
| 1065 | MockRead("Content-Length: 1337\r\n"), |
| 1066 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1067 | MockRead("5\r\nHello\r\n"), |
| 1068 | MockRead("1\r\n"), |
| 1069 | MockRead(" \r\n"), |
| 1070 | MockRead("5\r\nworld\r\n"), |
| 1071 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1073 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1074 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1075 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1076 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1077 | EXPECT_EQ("Hello world", out.response_data); |
| 1078 | } |
| 1079 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1080 | // Next tests deal with http://crbug.com/98895. |
| 1081 | |
| 1082 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1083 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1084 | MockRead data_reads[] = { |
| 1085 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1086 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1087 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1088 | MockRead("Hello"), |
| 1089 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1090 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1091 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1092 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1093 | EXPECT_EQ("Hello", out.response_data); |
| 1094 | } |
| 1095 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1096 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1097 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1098 | MockRead data_reads[] = { |
| 1099 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1100 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1101 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1102 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1103 | MockRead("Hello"), |
| 1104 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1105 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1106 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1107 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1108 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1112 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1113 | MockRead data_reads[] = { |
| 1114 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1115 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1116 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1117 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1118 | MockRead("Hello"), |
| 1119 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1120 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(out.rv, |
| 1122 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1125 | // Checks that two identical Location headers result in no error. |
| 1126 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1127 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1128 | MockRead data_reads[] = { |
| 1129 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1130 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1131 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1133 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1134 | }; |
| 1135 | |
| 1136 | HttpRequestInfo request; |
| 1137 | request.method = "GET"; |
| 1138 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1139 | request.traffic_annotation = |
| 1140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1141 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1143 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1144 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1145 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1148 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1150 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1153 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1155 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1156 | ASSERT_TRUE(response); |
| 1157 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1159 | std::string url; |
| 1160 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1161 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1162 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1165 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1166 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | MockRead data_reads[] = { |
| 1168 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1169 | MockRead("Location: http://good.com/\r\n"), |
| 1170 | MockRead("Location: http://evil.com/\r\n"), |
| 1171 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1172 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1173 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1174 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1175 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | } |
| 1177 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1178 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1179 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1180 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1181 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1182 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1183 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1184 | request.traffic_annotation = |
| 1185 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1186 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1189 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1190 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1191 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1192 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1193 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1194 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1195 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1196 | "Host: www.example.org\r\n" |
| 1197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1198 | }; |
| 1199 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1200 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1201 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1202 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1203 | // No response body because the test stops reading here. |
| 1204 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1205 | }; |
| 1206 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1207 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1210 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1211 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1212 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1213 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1214 | |
| 1215 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1218 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1219 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | |
| 1221 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1222 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1223 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1224 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1225 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1226 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1227 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | |
| 1229 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1230 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1231 | bool has_server_header = response->headers->EnumerateHeader( |
| 1232 | &iter, "Server", &server_header); |
| 1233 | EXPECT_TRUE(has_server_header); |
| 1234 | EXPECT_EQ("Blah", server_header); |
| 1235 | |
| 1236 | // Reading should give EOF right away, since there is no message body |
| 1237 | // (despite non-zero content-length). |
| 1238 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1239 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | EXPECT_EQ("", response_data); |
| 1242 | } |
| 1243 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1244 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1246 | |
| 1247 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1248 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1249 | MockRead("hello"), |
| 1250 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1251 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1252 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1253 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1254 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1256 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1257 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1258 | "hello", "world" |
| 1259 | }; |
| 1260 | |
| 1261 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1262 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1263 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1264 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1265 | request.traffic_annotation = |
| 1266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1268 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1270 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1271 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1272 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1274 | |
| 1275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1276 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1278 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1279 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1280 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1281 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1282 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1283 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | |
| 1285 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1286 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1288 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | } |
| 1290 | } |
| 1291 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1292 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1293 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1294 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1295 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1296 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1297 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1298 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | request.method = "POST"; |
| 1300 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1301 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1302 | request.traffic_annotation = |
| 1303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1305 | // Check the upload progress returned before initialization is correct. |
| 1306 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1307 | EXPECT_EQ(0u, progress.size()); |
| 1308 | EXPECT_EQ(0u, progress.position()); |
| 1309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1312 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1314 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1315 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1316 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1317 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1319 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1322 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1324 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | |
| 1327 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1328 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1330 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1331 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1333 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1334 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1335 | |
| 1336 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1337 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1338 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1339 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1340 | } |
| 1341 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1342 | // This test is almost the same as Ignores100 above, but the response contains |
| 1343 | // 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] | 1344 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1345 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1346 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1347 | request.method = "GET"; |
| 1348 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1349 | request.traffic_annotation = |
| 1350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1354 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1355 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1356 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1357 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1358 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1359 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1360 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1361 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1364 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1366 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1368 | |
| 1369 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1373 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1374 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1375 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1376 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1377 | |
| 1378 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | EXPECT_EQ("hello world", response_data); |
| 1382 | } |
| 1383 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1384 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1385 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1386 | base::TimeDelta::FromMilliseconds(10); |
| 1387 | |
| 1388 | HttpRequestInfo request; |
| 1389 | request.method = "GET"; |
| 1390 | request.url = GURL("http://www.foo.com/"); |
| 1391 | request.traffic_annotation = |
| 1392 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1393 | |
| 1394 | std::vector<MockWrite> data_writes = { |
| 1395 | MockWrite(ASYNC, 0, |
| 1396 | "GET / HTTP/1.1\r\n" |
| 1397 | "Host: www.foo.com\r\n" |
| 1398 | "Connection: keep-alive\r\n\r\n"), |
| 1399 | }; |
| 1400 | |
| 1401 | std::vector<MockRead> data_reads = { |
| 1402 | // Write one byte of the status line, followed by a pause. |
| 1403 | MockRead(ASYNC, 1, "H"), |
| 1404 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1405 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1406 | MockRead(ASYNC, 4, "hello world"), |
| 1407 | MockRead(SYNCHRONOUS, OK, 5), |
| 1408 | }; |
| 1409 | |
| 1410 | SequencedSocketData data(data_reads, data_writes); |
| 1411 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1412 | |
| 1413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1414 | |
| 1415 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1416 | |
| 1417 | TestCompletionCallback callback; |
| 1418 | |
| 1419 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1421 | |
| 1422 | data.RunUntilPaused(); |
| 1423 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1424 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1425 | data.Resume(); |
| 1426 | |
| 1427 | rv = callback.WaitForResult(); |
| 1428 | EXPECT_THAT(rv, IsOk()); |
| 1429 | |
| 1430 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1431 | ASSERT_TRUE(response); |
| 1432 | |
| 1433 | EXPECT_TRUE(response->headers); |
| 1434 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1435 | |
| 1436 | LoadTimingInfo load_timing_info; |
| 1437 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1438 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1439 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1440 | // Ensure we didn't include the delay in the TTFB time. |
| 1441 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1442 | load_timing_info.connect_timing.connect_end); |
| 1443 | // Ensure that the mock clock advanced at all. |
| 1444 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1445 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1446 | |
| 1447 | std::string response_data; |
| 1448 | rv = ReadTransaction(&trans, &response_data); |
| 1449 | EXPECT_THAT(rv, IsOk()); |
| 1450 | EXPECT_EQ("hello world", response_data); |
| 1451 | } |
| 1452 | |
| 1453 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1454 | // info uses the first response, even if 1XX/informational. |
| 1455 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1456 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1457 | base::TimeDelta::FromMilliseconds(10); |
| 1458 | |
| 1459 | HttpRequestInfo request; |
| 1460 | request.method = "GET"; |
| 1461 | request.url = GURL("https://www.foo.com/"); |
| 1462 | request.traffic_annotation = |
| 1463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1464 | |
| 1465 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1467 | |
| 1468 | std::vector<MockWrite> data_writes; |
| 1469 | std::vector<MockRead> data_reads; |
| 1470 | |
| 1471 | spdy::SpdySerializedFrame spdy_req( |
| 1472 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1473 | |
| 1474 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1475 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1476 | spdy::SpdySerializedFrame spdy_resp1( |
| 1477 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1478 | spdy::SpdySerializedFrame spdy_resp2( |
| 1479 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1480 | spdy::SpdySerializedFrame spdy_data( |
| 1481 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1482 | |
| 1483 | if (use_spdy) { |
| 1484 | ssl.next_proto = kProtoHTTP2; |
| 1485 | |
| 1486 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1487 | |
| 1488 | data_reads = { |
| 1489 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1490 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1491 | MockRead(SYNCHRONOUS, OK, 5), |
| 1492 | }; |
| 1493 | } else { |
| 1494 | data_writes = { |
| 1495 | MockWrite(ASYNC, 0, |
| 1496 | "GET / HTTP/1.1\r\n" |
| 1497 | "Host: www.foo.com\r\n" |
| 1498 | "Connection: keep-alive\r\n\r\n"), |
| 1499 | }; |
| 1500 | |
| 1501 | data_reads = { |
| 1502 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1503 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1504 | |
| 1505 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1506 | MockRead(ASYNC, 4, "hello world"), |
| 1507 | MockRead(SYNCHRONOUS, OK, 5), |
| 1508 | }; |
| 1509 | } |
| 1510 | |
| 1511 | SequencedSocketData data(data_reads, data_writes); |
| 1512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1513 | |
| 1514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1515 | |
| 1516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1517 | |
| 1518 | TestCompletionCallback callback; |
| 1519 | |
| 1520 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1522 | |
| 1523 | data.RunUntilPaused(); |
| 1524 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1525 | // the delay before parsing the 200 response. |
| 1526 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1527 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1528 | data.Resume(); |
| 1529 | |
| 1530 | rv = callback.WaitForResult(); |
| 1531 | EXPECT_THAT(rv, IsOk()); |
| 1532 | |
| 1533 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1534 | ASSERT_TRUE(response); |
| 1535 | |
| 1536 | LoadTimingInfo load_timing_info; |
| 1537 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1538 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1539 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1540 | // Ensure we didn't include the delay in the TTFB time. |
| 1541 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1542 | load_timing_info.connect_timing.connect_end); |
| 1543 | // Ensure that the mock clock advanced at all. |
| 1544 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1545 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1546 | |
| 1547 | std::string response_data; |
| 1548 | rv = ReadTransaction(&trans, &response_data); |
| 1549 | EXPECT_THAT(rv, IsOk()); |
| 1550 | EXPECT_EQ("hello world", response_data); |
| 1551 | } |
| 1552 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1553 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1554 | Check100ResponseTiming(false /* use_spdy */); |
| 1555 | } |
| 1556 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1557 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1558 | Check100ResponseTiming(true /* use_spdy */); |
| 1559 | } |
| 1560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1561 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1562 | HttpRequestInfo request; |
| 1563 | request.method = "POST"; |
| 1564 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1565 | request.traffic_annotation = |
| 1566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1570 | |
| 1571 | MockRead data_reads[] = { |
| 1572 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1573 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1574 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1575 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1576 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1577 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1578 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1579 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1580 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1582 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1583 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1584 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1585 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1586 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1587 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1588 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1589 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1590 | } |
| 1591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1592 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1593 | HttpRequestInfo request; |
| 1594 | request.method = "POST"; |
| 1595 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1596 | request.traffic_annotation = |
| 1597 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1601 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1602 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1603 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1604 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1605 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1608 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1612 | |
| 1613 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1614 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1615 | } |
| 1616 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1617 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1618 | const MockWrite* write_failure, |
| 1619 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1620 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1621 | request.method = "GET"; |
| 1622 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1623 | request.traffic_annotation = |
| 1624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1625 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1626 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1627 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1629 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1630 | // Written data for successfully sending both requests. |
| 1631 | MockWrite data1_writes[] = { |
| 1632 | MockWrite("GET / HTTP/1.1\r\n" |
| 1633 | "Host: www.foo.com\r\n" |
| 1634 | "Connection: keep-alive\r\n\r\n"), |
| 1635 | MockWrite("GET / HTTP/1.1\r\n" |
| 1636 | "Host: www.foo.com\r\n" |
| 1637 | "Connection: keep-alive\r\n\r\n") |
| 1638 | }; |
| 1639 | |
| 1640 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1641 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1642 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1643 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1644 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1645 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1646 | |
| 1647 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1648 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1649 | data1_writes[1] = *write_failure; |
| 1650 | } else { |
| 1651 | ASSERT_TRUE(read_failure); |
| 1652 | data1_reads[2] = *read_failure; |
| 1653 | } |
| 1654 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1655 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1656 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1657 | |
| 1658 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1659 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1660 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1661 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1662 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1663 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1664 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1665 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1666 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1667 | "hello", "world" |
| 1668 | }; |
| 1669 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1670 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1671 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1672 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1676 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1678 | |
| 1679 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1680 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1681 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1682 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1683 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1684 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1685 | if (i == 0) { |
| 1686 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1687 | } else { |
| 1688 | // The second request should be using a new socket. |
| 1689 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1690 | } |
| 1691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1692 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1693 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1694 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1695 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1696 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1697 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1698 | |
| 1699 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1700 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1702 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1703 | } |
| 1704 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1705 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1706 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1707 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1708 | const MockRead* read_failure, |
| 1709 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1710 | HttpRequestInfo request; |
| 1711 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1712 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1713 | request.traffic_annotation = |
| 1714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1715 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1716 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1717 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1719 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1720 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1721 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1722 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1723 | ssl1.next_proto = kProtoHTTP2; |
| 1724 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1725 | } |
| 1726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1728 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1729 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1730 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1731 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1732 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1733 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1734 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1735 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1736 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1737 | // HTTP/1.1 versions of the request and response. |
| 1738 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1739 | "Host: www.foo.com\r\n" |
| 1740 | "Connection: keep-alive\r\n\r\n"; |
| 1741 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1742 | const char kHttpData[] = "hello"; |
| 1743 | |
| 1744 | std::vector<MockRead> data1_reads; |
| 1745 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1746 | if (write_failure) { |
| 1747 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1748 | data1_writes.push_back(*write_failure); |
| 1749 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1750 | } else { |
| 1751 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1752 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1753 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1754 | } else { |
| 1755 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1756 | } |
| 1757 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | } |
| 1759 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1760 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1761 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1762 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | std::vector<MockRead> data2_reads; |
| 1764 | std::vector<MockWrite> data2_writes; |
| 1765 | |
| 1766 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1767 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1768 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1769 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1770 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1772 | } else { |
| 1773 | data2_writes.push_back( |
| 1774 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1775 | |
| 1776 | data2_reads.push_back( |
| 1777 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1778 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1779 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1780 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1781 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1782 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1783 | |
| 1784 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1785 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1786 | // Wait for the preconnect to complete. |
| 1787 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1788 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1789 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1790 | |
| 1791 | // Make the request. |
| 1792 | TestCompletionCallback callback; |
| 1793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1796 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1798 | |
| 1799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1800 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | |
| 1802 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1803 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1804 | TestLoadTimingNotReused( |
| 1805 | load_timing_info, |
| 1806 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1809 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1810 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1811 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1812 | if (response->was_fetched_via_spdy) { |
| 1813 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1814 | } else { |
| 1815 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1816 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1817 | |
| 1818 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1819 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1820 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1821 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1822 | } |
| 1823 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1824 | // 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] | 1825 | // ERR_HTTP2_PING_FAILED, ERR_HTTP2_SERVER_REFUSED_STREAM, |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1826 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1827 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1828 | HttpRequestInfo request; |
| 1829 | request.method = "GET"; |
| 1830 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1831 | request.traffic_annotation = |
| 1832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1833 | |
| 1834 | // Check whether we give up after the third try. |
| 1835 | |
| 1836 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1837 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1838 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1839 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1840 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1841 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1842 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1843 | |
| 1844 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1845 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1846 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1847 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1848 | |
| 1849 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1850 | AddSSLSocketData(); |
| 1851 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1852 | AddSSLSocketData(); |
| 1853 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1854 | AddSSLSocketData(); |
| 1855 | |
| 1856 | TestCompletionCallback callback; |
| 1857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1859 | |
| 1860 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1862 | |
| 1863 | rv = callback.WaitForResult(); |
Bence Béky | d0d6950 | 2019-06-25 19:47:18 | [diff] [blame] | 1864 | EXPECT_THAT(rv, IsError(ERR_HTTP2_SERVER_REFUSED_STREAM)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1868 | HttpRequestInfo request; |
| 1869 | request.method = "GET"; |
| 1870 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1871 | request.traffic_annotation = |
| 1872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1873 | |
| 1874 | // Check whether we try atleast thrice before giving up. |
| 1875 | |
| 1876 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1877 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1878 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1879 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1880 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1881 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1882 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1883 | |
| 1884 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1885 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1886 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1887 | spdy::SpdySerializedFrame spdy_data( |
| 1888 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1889 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1890 | CreateMockRead(spdy_data, 2)}; |
| 1891 | |
| 1892 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1893 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1894 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1895 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1896 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1897 | |
| 1898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1899 | AddSSLSocketData(); |
| 1900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1901 | AddSSLSocketData(); |
| 1902 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1903 | AddSSLSocketData(); |
| 1904 | |
| 1905 | TestCompletionCallback callback; |
| 1906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1908 | |
| 1909 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1911 | |
| 1912 | rv = callback.WaitForResult(); |
| 1913 | EXPECT_THAT(rv, IsOk()); |
| 1914 | } |
| 1915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1916 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1917 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1918 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1919 | } |
| 1920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1921 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1922 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1923 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1924 | } |
| 1925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1926 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1927 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1928 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1929 | } |
| 1930 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1931 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1932 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1933 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1934 | MockRead read_failure(SYNCHRONOUS, |
| 1935 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1936 | "Connection: Keep-Alive\r\n" |
| 1937 | "Content-Length: 6\r\n\r\n" |
| 1938 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1939 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1940 | } |
| 1941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1942 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1943 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1944 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1945 | } |
| 1946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1947 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1948 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1949 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1950 | } |
| 1951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1952 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1953 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1954 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1955 | } |
| 1956 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1957 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1958 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1959 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1960 | } |
| 1961 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1962 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1963 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1964 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1965 | MockRead read_failure(SYNCHRONOUS, |
| 1966 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1967 | "Connection: Keep-Alive\r\n" |
| 1968 | "Content-Length: 6\r\n\r\n" |
| 1969 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1970 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 1971 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1972 | } |
| 1973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1974 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1975 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1976 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1977 | } |
| 1978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1979 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1980 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1981 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1982 | } |
| 1983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1984 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1985 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1986 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1987 | } |
| 1988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1989 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1990 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1991 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1992 | } |
| 1993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1994 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1995 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1997 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1998 | request.traffic_annotation = |
| 1999 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2003 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2004 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2005 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2006 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2007 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2008 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2009 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2010 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2013 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2014 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2015 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2017 | |
| 2018 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2019 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2020 | |
| 2021 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2022 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2023 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | // What do various browsers do when the server closes a non-keepalive |
| 2027 | // connection without sending any response header or body? |
| 2028 | // |
| 2029 | // IE7: error page |
| 2030 | // Safari 3.1.2 (Windows): error page |
| 2031 | // Firefox 3.0.1: blank page |
| 2032 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2033 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2034 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2035 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2036 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2037 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2038 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2039 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2040 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2042 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2043 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2044 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2045 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2046 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2047 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2048 | // destructor in such situations. |
| 2049 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2050 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2051 | HttpRequestInfo request; |
| 2052 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2053 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2054 | request.traffic_annotation = |
| 2055 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2056 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2058 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2059 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2060 | |
| 2061 | MockRead data_reads[] = { |
| 2062 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2063 | MockRead("Connection: keep-alive\r\n"), |
| 2064 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2065 | MockRead("hello"), |
| 2066 | MockRead(SYNCHRONOUS, 0), |
| 2067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2068 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2069 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2070 | |
| 2071 | TestCompletionCallback callback; |
| 2072 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2073 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2075 | |
| 2076 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2077 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2078 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2079 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2080 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2081 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2082 | if (rv == ERR_IO_PENDING) |
| 2083 | rv = callback.WaitForResult(); |
| 2084 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2085 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2086 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2087 | |
| 2088 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2089 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2090 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2091 | } |
| 2092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2093 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2094 | HttpRequestInfo request; |
| 2095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2096 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2097 | request.traffic_annotation = |
| 2098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2101 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2102 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2103 | |
| 2104 | MockRead data_reads[] = { |
| 2105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2106 | MockRead("Connection: keep-alive\r\n"), |
| 2107 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2108 | MockRead(SYNCHRONOUS, 0), |
| 2109 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2110 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2111 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2112 | |
| 2113 | TestCompletionCallback callback; |
| 2114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2115 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2117 | |
| 2118 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2121 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2122 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2123 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2124 | if (rv == ERR_IO_PENDING) |
| 2125 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2126 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2127 | |
| 2128 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2129 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2130 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2131 | } |
| 2132 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2133 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2134 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2135 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2136 | HttpRequestInfo request; |
| 2137 | request.method = "GET"; |
| 2138 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2139 | request.traffic_annotation = |
| 2140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2141 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2142 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2143 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2145 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2146 | const char* request_data = |
| 2147 | "GET / HTTP/1.1\r\n" |
| 2148 | "Host: www.foo.com\r\n" |
| 2149 | "Connection: keep-alive\r\n\r\n"; |
| 2150 | MockWrite data_writes[] = { |
| 2151 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2152 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2153 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2154 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2155 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2156 | }; |
| 2157 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2158 | // Note that because all these reads happen in the same |
| 2159 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2160 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2161 | MockRead data_reads[] = { |
| 2162 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2163 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2164 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2165 | MockRead(ASYNC, 7, |
| 2166 | "HTTP/1.1 302 Found\r\n" |
| 2167 | "Content-Length: 0\r\n\r\n"), |
| 2168 | MockRead(ASYNC, 9, |
| 2169 | "HTTP/1.1 302 Found\r\n" |
| 2170 | "Content-Length: 5\r\n\r\n" |
| 2171 | "hello"), |
| 2172 | MockRead(ASYNC, 11, |
| 2173 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2174 | "Content-Length: 0\r\n\r\n"), |
| 2175 | MockRead(ASYNC, 13, |
| 2176 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2177 | "Content-Length: 5\r\n\r\n" |
| 2178 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2179 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2180 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2181 | // the set_busy_before_sync_reads(true) call, while the |
| 2182 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2183 | // reuseable. See http://crbug.com/544255. |
| 2184 | MockRead(ASYNC, 15, |
| 2185 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2186 | "Content-Length: 5\r\n\r\n"), |
| 2187 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2188 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2189 | MockRead(ASYNC, 18, |
| 2190 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2191 | "Content-Length: 5\r\n\r\n" |
| 2192 | "he"), |
| 2193 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2194 | |
| 2195 | // The body of the final request is actually read. |
| 2196 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2197 | MockRead(ASYNC, 22, "hello"), |
| 2198 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2199 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2200 | data.set_busy_before_sync_reads(true); |
| 2201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2202 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2203 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2204 | std::string response_lines[kNumUnreadBodies]; |
| 2205 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2206 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2207 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2208 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2209 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2210 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2211 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2213 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2214 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2215 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2216 | LoadTimingInfo load_timing_info; |
| 2217 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2218 | if (i == 0) { |
| 2219 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2220 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2221 | } else { |
| 2222 | TestLoadTimingReused(load_timing_info); |
| 2223 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2224 | } |
| 2225 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2227 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2228 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2229 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2230 | response_lines[i] = response->headers->GetStatusLine(); |
| 2231 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2232 | // Delete the transaction without reading the response bodies. Then spin |
| 2233 | // the message loop, so the response bodies are drained. |
| 2234 | trans.reset(); |
| 2235 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2236 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2237 | |
| 2238 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2239 | "HTTP/1.1 204 No Content", |
| 2240 | "HTTP/1.1 205 Reset Content", |
| 2241 | "HTTP/1.1 304 Not Modified", |
| 2242 | "HTTP/1.1 302 Found", |
| 2243 | "HTTP/1.1 302 Found", |
| 2244 | "HTTP/1.1 301 Moved Permanently", |
| 2245 | "HTTP/1.1 301 Moved Permanently", |
| 2246 | "HTTP/1.1 200 Hunky-Dory", |
| 2247 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2248 | }; |
| 2249 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2250 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2251 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2252 | |
| 2253 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2254 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2256 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2257 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2258 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2259 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2260 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2261 | ASSERT_TRUE(response); |
| 2262 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2263 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2264 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2265 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2267 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2268 | } |
| 2269 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2270 | // Sockets that receive extra data after a response is complete should not be |
| 2271 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2272 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2274 | MockWrite data_writes1[] = { |
| 2275 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2276 | "Host: www.borked.com\r\n" |
| 2277 | "Connection: keep-alive\r\n\r\n"), |
| 2278 | }; |
| 2279 | |
| 2280 | MockRead data_reads1[] = { |
| 2281 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2282 | "Connection: keep-alive\r\n" |
| 2283 | "Content-Length: 22\r\n\r\n" |
| 2284 | "This server is borked."), |
| 2285 | }; |
| 2286 | |
| 2287 | MockWrite data_writes2[] = { |
| 2288 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2289 | "Host: www.borked.com\r\n" |
| 2290 | "Connection: keep-alive\r\n\r\n"), |
| 2291 | }; |
| 2292 | |
| 2293 | MockRead data_reads2[] = { |
| 2294 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2295 | "Content-Length: 3\r\n\r\n" |
| 2296 | "foo"), |
| 2297 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2298 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2299 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2300 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2301 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2302 | |
| 2303 | TestCompletionCallback callback; |
| 2304 | HttpRequestInfo request1; |
| 2305 | request1.method = "HEAD"; |
| 2306 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2307 | request1.traffic_annotation = |
| 2308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2309 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2310 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2311 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2312 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2313 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2314 | |
| 2315 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2316 | ASSERT_TRUE(response1); |
| 2317 | ASSERT_TRUE(response1->headers); |
| 2318 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2319 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2320 | |
| 2321 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2322 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2323 | EXPECT_EQ("", response_data1); |
| 2324 | // Deleting the transaction attempts to release the socket back into the |
| 2325 | // socket pool. |
| 2326 | trans1.reset(); |
| 2327 | |
| 2328 | HttpRequestInfo request2; |
| 2329 | request2.method = "GET"; |
| 2330 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2331 | request2.traffic_annotation = |
| 2332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2333 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2334 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2335 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2336 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2337 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2338 | |
| 2339 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2340 | ASSERT_TRUE(response2); |
| 2341 | ASSERT_TRUE(response2->headers); |
| 2342 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2343 | |
| 2344 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2345 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2346 | EXPECT_EQ("foo", response_data2); |
| 2347 | } |
| 2348 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2349 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2351 | MockWrite data_writes1[] = { |
| 2352 | MockWrite("GET / HTTP/1.1\r\n" |
| 2353 | "Host: www.borked.com\r\n" |
| 2354 | "Connection: keep-alive\r\n\r\n"), |
| 2355 | }; |
| 2356 | |
| 2357 | MockRead data_reads1[] = { |
| 2358 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2359 | "Connection: keep-alive\r\n" |
| 2360 | "Content-Length: 22\r\n\r\n" |
| 2361 | "This server is borked." |
| 2362 | "Bonus data!"), |
| 2363 | }; |
| 2364 | |
| 2365 | MockWrite data_writes2[] = { |
| 2366 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2367 | "Host: www.borked.com\r\n" |
| 2368 | "Connection: keep-alive\r\n\r\n"), |
| 2369 | }; |
| 2370 | |
| 2371 | MockRead data_reads2[] = { |
| 2372 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2373 | "Content-Length: 3\r\n\r\n" |
| 2374 | "foo"), |
| 2375 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2376 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2377 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2378 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2379 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2380 | |
| 2381 | TestCompletionCallback callback; |
| 2382 | HttpRequestInfo request1; |
| 2383 | request1.method = "GET"; |
| 2384 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2385 | request1.traffic_annotation = |
| 2386 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2387 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2388 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2389 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2390 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2391 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2392 | |
| 2393 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2394 | ASSERT_TRUE(response1); |
| 2395 | ASSERT_TRUE(response1->headers); |
| 2396 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2397 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2398 | |
| 2399 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2400 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2401 | EXPECT_EQ("This server is borked.", response_data1); |
| 2402 | // Deleting the transaction attempts to release the socket back into the |
| 2403 | // socket pool. |
| 2404 | trans1.reset(); |
| 2405 | |
| 2406 | HttpRequestInfo request2; |
| 2407 | request2.method = "GET"; |
| 2408 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2409 | request2.traffic_annotation = |
| 2410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2411 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2412 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2413 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2414 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2415 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2416 | |
| 2417 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2418 | ASSERT_TRUE(response2); |
| 2419 | ASSERT_TRUE(response2->headers); |
| 2420 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2421 | |
| 2422 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2423 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2424 | EXPECT_EQ("foo", response_data2); |
| 2425 | } |
| 2426 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2427 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2429 | MockWrite data_writes1[] = { |
| 2430 | MockWrite("GET / HTTP/1.1\r\n" |
| 2431 | "Host: www.borked.com\r\n" |
| 2432 | "Connection: keep-alive\r\n\r\n"), |
| 2433 | }; |
| 2434 | |
| 2435 | MockRead data_reads1[] = { |
| 2436 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2437 | "Connection: keep-alive\r\n" |
| 2438 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2439 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2440 | MockRead("0\r\n\r\nBonus data!"), |
| 2441 | }; |
| 2442 | |
| 2443 | MockWrite data_writes2[] = { |
| 2444 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2445 | "Host: www.borked.com\r\n" |
| 2446 | "Connection: keep-alive\r\n\r\n"), |
| 2447 | }; |
| 2448 | |
| 2449 | MockRead data_reads2[] = { |
| 2450 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2451 | "Content-Length: 3\r\n\r\n" |
| 2452 | "foo"), |
| 2453 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2454 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2455 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2456 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2457 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2458 | |
| 2459 | TestCompletionCallback callback; |
| 2460 | HttpRequestInfo request1; |
| 2461 | request1.method = "GET"; |
| 2462 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2463 | request1.traffic_annotation = |
| 2464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2465 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2466 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2467 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2468 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2469 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2470 | |
| 2471 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2472 | ASSERT_TRUE(response1); |
| 2473 | ASSERT_TRUE(response1->headers); |
| 2474 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2475 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2476 | |
| 2477 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2478 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2479 | EXPECT_EQ("This server is borked.", response_data1); |
| 2480 | // Deleting the transaction attempts to release the socket back into the |
| 2481 | // socket pool. |
| 2482 | trans1.reset(); |
| 2483 | |
| 2484 | HttpRequestInfo request2; |
| 2485 | request2.method = "GET"; |
| 2486 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2487 | request2.traffic_annotation = |
| 2488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2489 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2490 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2491 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2492 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2493 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2494 | |
| 2495 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2496 | ASSERT_TRUE(response2); |
| 2497 | ASSERT_TRUE(response2->headers); |
| 2498 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2499 | |
| 2500 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2501 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2502 | EXPECT_EQ("foo", response_data2); |
| 2503 | } |
| 2504 | |
| 2505 | // This is a little different from the others - it tests the case that the |
| 2506 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2507 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2508 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2509 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2510 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2511 | MockWrite data_writes1[] = { |
| 2512 | MockWrite("GET / HTTP/1.1\r\n" |
| 2513 | "Host: www.borked.com\r\n" |
| 2514 | "Connection: keep-alive\r\n\r\n"), |
| 2515 | }; |
| 2516 | |
| 2517 | MockRead data_reads1[] = { |
| 2518 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2519 | "Connection: keep-alive\r\n" |
| 2520 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2521 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2522 | MockRead("0\r\n\r\nBonus data!"), |
| 2523 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2524 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2526 | |
| 2527 | TestCompletionCallback callback; |
| 2528 | HttpRequestInfo request1; |
| 2529 | request1.method = "GET"; |
| 2530 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2531 | request1.traffic_annotation = |
| 2532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2533 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2534 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2535 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2536 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2537 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2538 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2539 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2540 | ASSERT_TRUE(response1); |
| 2541 | ASSERT_TRUE(response1->headers); |
| 2542 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2543 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2544 | |
| 2545 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2546 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2547 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2548 | |
| 2549 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2550 | // socket can't be reused, rather than returning it to the socket pool. |
| 2551 | base::RunLoop().RunUntilIdle(); |
| 2552 | |
| 2553 | // There should be no idle sockets in the pool. |
| 2554 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2555 | } |
| 2556 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2557 | // Test the request-challenge-retry sequence for basic auth. |
| 2558 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2559 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2560 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2561 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2562 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2563 | request.traffic_annotation = |
| 2564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2565 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2566 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2567 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2570 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2571 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2572 | MockWrite( |
| 2573 | "GET / HTTP/1.1\r\n" |
| 2574 | "Host: www.example.org\r\n" |
| 2575 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2576 | }; |
| 2577 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2578 | MockRead data_reads1[] = { |
| 2579 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2580 | // Give a couple authenticate options (only the middle one is actually |
| 2581 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2582 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2583 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2584 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2586 | // Large content-length -- won't matter, as connection will be reset. |
| 2587 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2588 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2589 | }; |
| 2590 | |
| 2591 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2592 | // be issuing -- the final header line contains the credentials. |
| 2593 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2594 | MockWrite( |
| 2595 | "GET / HTTP/1.1\r\n" |
| 2596 | "Host: www.example.org\r\n" |
| 2597 | "Connection: keep-alive\r\n" |
| 2598 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2599 | }; |
| 2600 | |
| 2601 | // Lastly, the server responds with the actual content. |
| 2602 | MockRead data_reads2[] = { |
| 2603 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2604 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2605 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2606 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2607 | }; |
| 2608 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2609 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2610 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2611 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2612 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2614 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2615 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2616 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2617 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2618 | |
| 2619 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2620 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2621 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2622 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2623 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2624 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2625 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2626 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2627 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2628 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2629 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2631 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2632 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2633 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2635 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2637 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2639 | |
| 2640 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2641 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2642 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2643 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2644 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2645 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2646 | // The load timing after restart should have a new socket ID, and times after |
| 2647 | // those of the first load timing. |
| 2648 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2649 | load_timing_info2.connect_timing.connect_start); |
| 2650 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2652 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2654 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2655 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2657 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2658 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2659 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2660 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2661 | } |
| 2662 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2663 | // Test the request-challenge-retry sequence for basic auth. |
| 2664 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2665 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2666 | HttpRequestInfo request; |
| 2667 | request.method = "GET"; |
| 2668 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2669 | request.traffic_annotation = |
| 2670 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2671 | |
| 2672 | TestNetLog log; |
| 2673 | MockHostResolver* resolver = new MockHostResolver(); |
| 2674 | session_deps_.net_log = &log; |
| 2675 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2676 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2678 | |
| 2679 | resolver->rules()->ClearRules(); |
| 2680 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2681 | |
| 2682 | MockWrite data_writes1[] = { |
| 2683 | MockWrite("GET / HTTP/1.1\r\n" |
| 2684 | "Host: www.example.org\r\n" |
| 2685 | "Connection: keep-alive\r\n\r\n"), |
| 2686 | }; |
| 2687 | |
| 2688 | MockRead data_reads1[] = { |
| 2689 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2690 | // Give a couple authenticate options (only the middle one is actually |
| 2691 | // supported). |
| 2692 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2693 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2694 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2695 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2696 | // Large content-length -- won't matter, as connection will be reset. |
| 2697 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2698 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2699 | }; |
| 2700 | |
| 2701 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2702 | // be issuing -- the final header line contains the credentials. |
| 2703 | MockWrite data_writes2[] = { |
| 2704 | MockWrite("GET / HTTP/1.1\r\n" |
| 2705 | "Host: www.example.org\r\n" |
| 2706 | "Connection: keep-alive\r\n" |
| 2707 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2708 | }; |
| 2709 | |
| 2710 | // Lastly, the server responds with the actual content. |
| 2711 | MockRead data_reads2[] = { |
| 2712 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2713 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2714 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2715 | }; |
| 2716 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2717 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2718 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2719 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2720 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2721 | |
| 2722 | TestCompletionCallback callback1; |
| 2723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2724 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2725 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2726 | |
| 2727 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2728 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2729 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2730 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2731 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2732 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2733 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2734 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2736 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2737 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2738 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2739 | |
| 2740 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2742 | ASSERT_FALSE(endpoint.address().empty()); |
| 2743 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2744 | |
| 2745 | resolver->rules()->ClearRules(); |
| 2746 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2747 | |
| 2748 | TestCompletionCallback callback2; |
| 2749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2750 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2751 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2752 | |
| 2753 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2754 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2755 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2756 | // The load timing after restart should have a new socket ID, and times after |
| 2757 | // those of the first load timing. |
| 2758 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2759 | load_timing_info2.connect_timing.connect_start); |
| 2760 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2762 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2763 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2764 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2765 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2768 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2769 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2770 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2771 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2772 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2773 | ASSERT_FALSE(endpoint.address().empty()); |
| 2774 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2775 | } |
| 2776 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2777 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2778 | // will eventually give up. |
| 2779 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2780 | HttpRequestInfo request; |
| 2781 | request.method = "GET"; |
| 2782 | request.url = GURL("http://www.example.org/"); |
| 2783 | request.traffic_annotation = |
| 2784 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2785 | |
| 2786 | TestNetLog log; |
| 2787 | session_deps_.net_log = &log; |
| 2788 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2789 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2790 | |
| 2791 | MockWrite data_writes[] = { |
| 2792 | MockWrite("GET / HTTP/1.1\r\n" |
| 2793 | "Host: www.example.org\r\n" |
| 2794 | "Connection: keep-alive\r\n\r\n"), |
| 2795 | }; |
| 2796 | |
| 2797 | MockRead data_reads[] = { |
| 2798 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2799 | // Give a couple authenticate options (only the middle one is actually |
| 2800 | // supported). |
| 2801 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2802 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2803 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2804 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2805 | // Large content-length -- won't matter, as connection will be reset. |
| 2806 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2807 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2808 | }; |
| 2809 | |
| 2810 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2811 | // be issuing -- the final header line contains the credentials. |
| 2812 | MockWrite data_writes_restart[] = { |
| 2813 | MockWrite("GET / HTTP/1.1\r\n" |
| 2814 | "Host: www.example.org\r\n" |
| 2815 | "Connection: keep-alive\r\n" |
| 2816 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2817 | }; |
| 2818 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2819 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2821 | |
| 2822 | TestCompletionCallback callback; |
| 2823 | int rv = callback.GetResult( |
| 2824 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2825 | |
| 2826 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2827 | for (int i = 0; i < 32; i++) { |
| 2828 | // Check the previous response was a 401. |
| 2829 | EXPECT_THAT(rv, IsOk()); |
| 2830 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2831 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2832 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2833 | |
| 2834 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2835 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2836 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2837 | data_restarts.back().get()); |
| 2838 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2839 | callback.callback())); |
| 2840 | } |
| 2841 | |
| 2842 | // After too many tries, the transaction should have given up. |
| 2843 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2844 | } |
| 2845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2846 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2847 | HttpRequestInfo request; |
| 2848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2849 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2850 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2851 | request.traffic_annotation = |
| 2852 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2853 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2856 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2857 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2858 | MockWrite( |
| 2859 | "GET / HTTP/1.1\r\n" |
| 2860 | "Host: www.example.org\r\n" |
| 2861 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2862 | }; |
| 2863 | |
| 2864 | MockRead data_reads[] = { |
| 2865 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2866 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2867 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2868 | // Large content-length -- won't matter, as connection will be reset. |
| 2869 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2870 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2871 | }; |
| 2872 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2873 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2874 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2875 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2877 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2879 | |
| 2880 | rv = callback.WaitForResult(); |
| 2881 | EXPECT_EQ(0, rv); |
| 2882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2883 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2884 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2885 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2886 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2888 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2889 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2890 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2891 | } |
| 2892 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2893 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2894 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2895 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2896 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2897 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2898 | // reused. See http://crbug.com/544255. |
| 2899 | for (int i = 0; i < 2; ++i) { |
| 2900 | HttpRequestInfo request; |
| 2901 | request.method = "GET"; |
| 2902 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2903 | request.traffic_annotation = |
| 2904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2905 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2906 | TestNetLog log; |
| 2907 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2909 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2910 | MockWrite data_writes[] = { |
| 2911 | MockWrite(ASYNC, 0, |
| 2912 | "GET / HTTP/1.1\r\n" |
| 2913 | "Host: www.example.org\r\n" |
| 2914 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2916 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2917 | // be issuing -- the final header line contains the credentials. |
| 2918 | MockWrite(ASYNC, 6, |
| 2919 | "GET / HTTP/1.1\r\n" |
| 2920 | "Host: www.example.org\r\n" |
| 2921 | "Connection: keep-alive\r\n" |
| 2922 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2923 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2924 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2925 | MockRead data_reads[] = { |
| 2926 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2927 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2928 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2929 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2930 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2931 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2932 | // Lastly, the server responds with the actual content. |
| 2933 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2934 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2935 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2936 | MockRead(ASYNC, 10, "Hello"), |
| 2937 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2938 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2939 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2940 | data.set_busy_before_sync_reads(true); |
| 2941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2942 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2943 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2946 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2947 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2948 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2949 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2950 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2951 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2954 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2955 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2957 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2959 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2960 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2961 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2962 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2963 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2964 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2965 | TestLoadTimingReused(load_timing_info2); |
| 2966 | // The load timing after restart should have the same socket ID, and times |
| 2967 | // those of the first load timing. |
| 2968 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2969 | load_timing_info2.send_start); |
| 2970 | 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] | 2971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2972 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2973 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2974 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2975 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2976 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2977 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2978 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2980 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2981 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2982 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2983 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2984 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2988 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2989 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2990 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2991 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2992 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2993 | request.traffic_annotation = |
| 2994 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2997 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2998 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2999 | MockWrite("GET / HTTP/1.1\r\n" |
| 3000 | "Host: www.example.org\r\n" |
| 3001 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3003 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3004 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3005 | MockWrite("GET / HTTP/1.1\r\n" |
| 3006 | "Host: www.example.org\r\n" |
| 3007 | "Connection: keep-alive\r\n" |
| 3008 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3009 | }; |
| 3010 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3011 | MockRead data_reads1[] = { |
| 3012 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3013 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3014 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3015 | |
| 3016 | // Lastly, the server responds with the actual content. |
| 3017 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3019 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3020 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | }; |
| 3022 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3023 | // An incorrect reconnect would cause this to be read. |
| 3024 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3025 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3026 | }; |
| 3027 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3028 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3029 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3030 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3031 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3033 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3036 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | |
| 3039 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3040 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3042 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3043 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3044 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3046 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3048 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3050 | |
| 3051 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3054 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3055 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3056 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3057 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3061 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3062 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3063 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3065 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3066 | request.traffic_annotation = |
| 3067 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3070 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3071 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3072 | MockWrite("GET / HTTP/1.1\r\n" |
| 3073 | "Host: www.example.org\r\n" |
| 3074 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3076 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3077 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3078 | MockWrite("GET / HTTP/1.1\r\n" |
| 3079 | "Host: www.example.org\r\n" |
| 3080 | "Connection: keep-alive\r\n" |
| 3081 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3082 | }; |
| 3083 | |
| 3084 | // Respond with 5 kb of response body. |
| 3085 | std::string large_body_string("Unauthorized"); |
| 3086 | large_body_string.append(5 * 1024, ' '); |
| 3087 | large_body_string.append("\r\n"); |
| 3088 | |
| 3089 | MockRead data_reads1[] = { |
| 3090 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3091 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3092 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3093 | // 5134 = 12 + 5 * 1024 + 2 |
| 3094 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3095 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3096 | |
| 3097 | // Lastly, the server responds with the actual content. |
| 3098 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3099 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3100 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3101 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3102 | }; |
| 3103 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3104 | // An incorrect reconnect would cause this to be read. |
| 3105 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3106 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3107 | }; |
| 3108 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3109 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3110 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3111 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3112 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3114 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3117 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3119 | |
| 3120 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3121 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3124 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3125 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3127 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3129 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3131 | |
| 3132 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3135 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3136 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3137 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3138 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3142 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3143 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3144 | HttpRequestInfo request; |
| 3145 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3146 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3147 | request.traffic_annotation = |
| 3148 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3149 | |
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 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3152 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3153 | MockWrite( |
| 3154 | "GET / HTTP/1.1\r\n" |
| 3155 | "Host: www.example.org\r\n" |
| 3156 | "Connection: keep-alive\r\n\r\n"), |
| 3157 | // This simulates the seemingly successful write to a closed connection |
| 3158 | // if the bug is not fixed. |
| 3159 | MockWrite( |
| 3160 | "GET / HTTP/1.1\r\n" |
| 3161 | "Host: www.example.org\r\n" |
| 3162 | "Connection: keep-alive\r\n" |
| 3163 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3164 | }; |
| 3165 | |
| 3166 | MockRead data_reads1[] = { |
| 3167 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3168 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3169 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3170 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3171 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3172 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3173 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3174 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3175 | }; |
| 3176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3177 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3178 | // be issuing -- the final header line contains the credentials. |
| 3179 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3180 | MockWrite( |
| 3181 | "GET / HTTP/1.1\r\n" |
| 3182 | "Host: www.example.org\r\n" |
| 3183 | "Connection: keep-alive\r\n" |
| 3184 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3185 | }; |
| 3186 | |
| 3187 | // Lastly, the server responds with the actual content. |
| 3188 | MockRead data_reads2[] = { |
| 3189 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3190 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3191 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3192 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3193 | }; |
| 3194 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3195 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3196 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3198 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3200 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3203 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3204 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3205 | |
| 3206 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3207 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3209 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3210 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3211 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3213 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3215 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3217 | |
| 3218 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3221 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3222 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3223 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3224 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3225 | } |
| 3226 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3227 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3228 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3229 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3230 | HttpRequestInfo request; |
| 3231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3232 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3233 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3234 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3235 | request.traffic_annotation = |
| 3236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3237 | |
| 3238 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3239 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3240 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3241 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3242 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3243 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3244 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3245 | |
| 3246 | // Since we have proxy, should try to establish tunnel. |
| 3247 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3248 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3249 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3250 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3251 | }; |
| 3252 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3253 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3254 | // connection. |
| 3255 | MockRead data_reads1[] = { |
| 3256 | // No credentials. |
| 3257 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3258 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3259 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3260 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3261 | // Since the first connection couldn't be reused, need to establish another |
| 3262 | // once given credentials. |
| 3263 | MockWrite data_writes2[] = { |
| 3264 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3265 | // be issuing -- the final header line contains the credentials. |
| 3266 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3267 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3268 | "Proxy-Connection: keep-alive\r\n" |
| 3269 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3270 | |
| 3271 | MockWrite("GET / HTTP/1.1\r\n" |
| 3272 | "Host: www.example.org\r\n" |
| 3273 | "Connection: keep-alive\r\n\r\n"), |
| 3274 | }; |
| 3275 | |
| 3276 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3278 | |
| 3279 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3280 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3281 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3282 | MockRead(SYNCHRONOUS, "hello"), |
| 3283 | }; |
| 3284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3285 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3287 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3288 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3289 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3291 | |
| 3292 | TestCompletionCallback callback1; |
| 3293 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3294 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3295 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3296 | |
| 3297 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3299 | |
| 3300 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3301 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3302 | auto entries = log.GetEntries(); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3304 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3305 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3306 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3307 | entries, pos, |
| 3308 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3309 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3310 | |
| 3311 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3312 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3313 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3314 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3315 | EXPECT_EQ(407, response->headers->response_code()); |
| 3316 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3317 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3318 | |
| 3319 | LoadTimingInfo load_timing_info; |
| 3320 | // CONNECT requests and responses are handled at the connect job level, so |
| 3321 | // the transaction does not yet have a connection. |
| 3322 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3323 | |
| 3324 | TestCompletionCallback callback2; |
| 3325 | |
| 3326 | rv = |
| 3327 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | |
| 3330 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3331 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3332 | |
| 3333 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3334 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3335 | |
| 3336 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3337 | EXPECT_EQ(200, response->headers->response_code()); |
| 3338 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3339 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3340 | |
| 3341 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3342 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3343 | |
| 3344 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3345 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3346 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3347 | |
| 3348 | trans.reset(); |
| 3349 | session->CloseAllConnections(); |
| 3350 | } |
| 3351 | |
| 3352 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3353 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3354 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3355 | HttpRequestInfo request; |
| 3356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3357 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3358 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3359 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3360 | request.traffic_annotation = |
| 3361 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3362 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3363 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3364 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3365 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3366 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3367 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3368 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3370 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3371 | // Since we have proxy, should try to establish tunnel. |
| 3372 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3373 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3374 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3375 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3376 | }; |
| 3377 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3378 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3379 | // connection. |
| 3380 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3381 | // No credentials. |
| 3382 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3383 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3384 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3385 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3386 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3387 | MockWrite data_writes2[] = { |
| 3388 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3389 | // be issuing -- the final header line contains the credentials. |
| 3390 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3391 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3392 | "Proxy-Connection: keep-alive\r\n" |
| 3393 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3394 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3395 | MockWrite("GET / HTTP/1.1\r\n" |
| 3396 | "Host: www.example.org\r\n" |
| 3397 | "Connection: keep-alive\r\n\r\n"), |
| 3398 | }; |
| 3399 | |
| 3400 | MockRead data_reads2[] = { |
| 3401 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3402 | |
| 3403 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3404 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3405 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3406 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3407 | }; |
| 3408 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3409 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3411 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3412 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3413 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3416 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3417 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3418 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3419 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3420 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3421 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3423 | |
| 3424 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3425 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3426 | auto entries = log.GetEntries(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3427 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3428 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3429 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3430 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3431 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3432 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3433 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3434 | |
| 3435 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3436 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3437 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3438 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3439 | EXPECT_EQ(407, response->headers->response_code()); |
| 3440 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3441 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3442 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3443 | LoadTimingInfo load_timing_info; |
| 3444 | // CONNECT requests and responses are handled at the connect job level, so |
| 3445 | // the transaction does not yet have a connection. |
| 3446 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3448 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3450 | rv = trans->RestartWithAuth( |
| 3451 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3453 | |
| 3454 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3455 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3456 | |
| 3457 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3458 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | |
| 3460 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3461 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3462 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3463 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3464 | |
| 3465 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3466 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3467 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3468 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3469 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3470 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3471 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3472 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3473 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3474 | } |
| 3475 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3476 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3477 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3478 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3479 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3480 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3481 | // reused. See http://crbug.com/544255. |
| 3482 | for (int i = 0; i < 2; ++i) { |
| 3483 | HttpRequestInfo request; |
| 3484 | request.method = "GET"; |
| 3485 | request.url = GURL("https://www.example.org/"); |
| 3486 | // Ensure that proxy authentication is attempted even |
| 3487 | // when the no authentication data flag is set. |
| 3488 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3489 | request.traffic_annotation = |
| 3490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3491 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3492 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3493 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3494 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3495 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3496 | BoundTestNetLog log; |
| 3497 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3501 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3502 | // Since we have proxy, should try to establish tunnel. |
| 3503 | MockWrite data_writes1[] = { |
| 3504 | MockWrite(ASYNC, 0, |
| 3505 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3506 | "Host: www.example.org:443\r\n" |
| 3507 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3509 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3510 | // be issuing -- the final header line contains the credentials. |
| 3511 | MockWrite(ASYNC, 3, |
| 3512 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3513 | "Host: www.example.org:443\r\n" |
| 3514 | "Proxy-Connection: keep-alive\r\n" |
| 3515 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3516 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3517 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3518 | // The proxy responds to the connect with a 407, using a persistent |
| 3519 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3520 | MockRead data_reads1[] = { |
| 3521 | // No credentials. |
| 3522 | MockRead(ASYNC, 1, |
| 3523 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3524 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3525 | "Proxy-Connection: keep-alive\r\n" |
| 3526 | "Content-Length: 10\r\n\r\n"), |
| 3527 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3528 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3529 | // Wrong credentials (wrong password). |
| 3530 | MockRead(ASYNC, 4, |
| 3531 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3532 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3533 | "Proxy-Connection: keep-alive\r\n" |
| 3534 | "Content-Length: 10\r\n\r\n"), |
| 3535 | // No response body because the test stops reading here. |
| 3536 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3537 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3538 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3539 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3540 | data1.set_busy_before_sync_reads(true); |
| 3541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3542 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3543 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3545 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3546 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3547 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3548 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3549 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3550 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3551 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3552 | ExpectLogContainsSomewhere( |
| 3553 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3554 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3555 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3558 | ASSERT_TRUE(response); |
| 3559 | ASSERT_TRUE(response->headers); |
| 3560 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3561 | EXPECT_EQ(407, response->headers->response_code()); |
| 3562 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3563 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3564 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3565 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3567 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3568 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3569 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3570 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3571 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3573 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3574 | ASSERT_TRUE(response); |
| 3575 | ASSERT_TRUE(response->headers); |
| 3576 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3577 | EXPECT_EQ(407, response->headers->response_code()); |
| 3578 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3579 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3580 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3581 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3582 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3583 | // out of scope. |
| 3584 | session->CloseAllConnections(); |
| 3585 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3589 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3590 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3591 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3592 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3593 | // reused. See http://crbug.com/544255. |
| 3594 | for (int i = 0; i < 2; ++i) { |
| 3595 | HttpRequestInfo request; |
| 3596 | request.method = "GET"; |
| 3597 | request.url = GURL("https://www.example.org/"); |
| 3598 | // Ensure that proxy authentication is attempted even |
| 3599 | // when the no authentication data flag is set. |
| 3600 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3601 | request.traffic_annotation = |
| 3602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | |
| 3604 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3605 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3606 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3607 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3608 | BoundTestNetLog log; |
| 3609 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3613 | |
| 3614 | // Since we have proxy, should try to establish tunnel. |
| 3615 | MockWrite data_writes1[] = { |
| 3616 | MockWrite(ASYNC, 0, |
| 3617 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3618 | "Host: www.example.org:443\r\n" |
| 3619 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3620 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3621 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3622 | // be issuing -- the final header line contains the credentials. |
| 3623 | MockWrite(ASYNC, 3, |
| 3624 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3625 | "Host: www.example.org:443\r\n" |
| 3626 | "Proxy-Connection: keep-alive\r\n" |
| 3627 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3628 | }; |
| 3629 | |
| 3630 | // The proxy responds to the connect with a 407, using a persistent |
| 3631 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3632 | MockRead data_reads1[] = { |
| 3633 | // No credentials. |
| 3634 | MockRead(ASYNC, 1, |
| 3635 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3636 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3637 | "Content-Length: 10\r\n\r\n"), |
| 3638 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3639 | |
| 3640 | // Wrong credentials (wrong password). |
| 3641 | MockRead(ASYNC, 4, |
| 3642 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3643 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3644 | "Content-Length: 10\r\n\r\n"), |
| 3645 | // No response body because the test stops reading here. |
| 3646 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3647 | }; |
| 3648 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3649 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3650 | data1.set_busy_before_sync_reads(true); |
| 3651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3652 | |
| 3653 | TestCompletionCallback callback1; |
| 3654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3655 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3656 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3658 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3659 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3660 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3661 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3662 | ExpectLogContainsSomewhere( |
| 3663 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3664 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3665 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3668 | ASSERT_TRUE(response); |
| 3669 | ASSERT_TRUE(response->headers); |
| 3670 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3671 | EXPECT_EQ(407, response->headers->response_code()); |
| 3672 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3673 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3674 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3675 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | |
| 3677 | TestCompletionCallback callback2; |
| 3678 | |
| 3679 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3680 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3681 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3682 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3684 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3685 | ASSERT_TRUE(response); |
| 3686 | ASSERT_TRUE(response->headers); |
| 3687 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3688 | EXPECT_EQ(407, response->headers->response_code()); |
| 3689 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3690 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3691 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3692 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3693 | |
| 3694 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3695 | // out of scope. |
| 3696 | session->CloseAllConnections(); |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3701 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3702 | // the case the server sends extra data on the original socket, so it can't be |
| 3703 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3704 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3705 | HttpRequestInfo request; |
| 3706 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3707 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3708 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3709 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3710 | request.traffic_annotation = |
| 3711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3712 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3713 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3714 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3715 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3716 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3717 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3718 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3720 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3721 | // Since we have proxy, should try to establish tunnel. |
| 3722 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3723 | MockWrite(ASYNC, 0, |
| 3724 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3725 | "Host: www.example.org:443\r\n" |
| 3726 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3727 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3728 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3730 | // extra data, so the socket cannot be reused. |
| 3731 | MockRead data_reads1[] = { |
| 3732 | // No credentials. |
| 3733 | MockRead(ASYNC, 1, |
| 3734 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3735 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3736 | "Content-Length: 10\r\n\r\n"), |
| 3737 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3738 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3739 | }; |
| 3740 | |
| 3741 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3742 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3743 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3744 | MockWrite(ASYNC, 0, |
| 3745 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3746 | "Host: www.example.org:443\r\n" |
| 3747 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3748 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3749 | |
| 3750 | MockWrite(ASYNC, 2, |
| 3751 | "GET / HTTP/1.1\r\n" |
| 3752 | "Host: www.example.org\r\n" |
| 3753 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3754 | }; |
| 3755 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3756 | MockRead data_reads2[] = { |
| 3757 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3758 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3759 | MockRead(ASYNC, 3, |
| 3760 | "HTTP/1.1 200 OK\r\n" |
| 3761 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3762 | "Content-Length: 5\r\n\r\n"), |
| 3763 | // No response body because the test stops reading here. |
| 3764 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3765 | }; |
| 3766 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3767 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3768 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3769 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3770 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3771 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3772 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3775 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3776 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3777 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3778 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3779 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3780 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3781 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3782 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3783 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3784 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3785 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3786 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3787 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3788 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3789 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3790 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3791 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3792 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3793 | ASSERT_TRUE(response); |
| 3794 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3795 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3796 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3797 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3798 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3799 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3800 | LoadTimingInfo load_timing_info; |
| 3801 | // CONNECT requests and responses are handled at the connect job level, so |
| 3802 | // the transaction does not yet have a connection. |
| 3803 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3804 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3805 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3806 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3807 | rv = |
| 3808 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3809 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3810 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3811 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3812 | EXPECT_EQ(200, response->headers->response_code()); |
| 3813 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3814 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3815 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3816 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3817 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3818 | |
| 3819 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3820 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3821 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3822 | |
| 3823 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3824 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3825 | } |
| 3826 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3827 | // Test the case a proxy closes a socket while the challenge body is being |
| 3828 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3829 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3830 | HttpRequestInfo request; |
| 3831 | request.method = "GET"; |
| 3832 | request.url = GURL("https://www.example.org/"); |
| 3833 | // Ensure that proxy authentication is attempted even |
| 3834 | // when the no authentication data flag is set. |
| 3835 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3836 | request.traffic_annotation = |
| 3837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3838 | |
| 3839 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3840 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3841 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3842 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3845 | |
| 3846 | // Since we have proxy, should try to establish tunnel. |
| 3847 | MockWrite data_writes1[] = { |
| 3848 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3849 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3850 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3851 | }; |
| 3852 | |
| 3853 | // The proxy responds to the connect with a 407, using a persistent |
| 3854 | // connection. |
| 3855 | MockRead data_reads1[] = { |
| 3856 | // No credentials. |
| 3857 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3858 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3859 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3860 | // Server hands up in the middle of the body. |
| 3861 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3862 | }; |
| 3863 | |
| 3864 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3865 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3866 | // be issuing -- the final header line contains the credentials. |
| 3867 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3868 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3869 | "Proxy-Connection: keep-alive\r\n" |
| 3870 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3871 | |
| 3872 | MockWrite("GET / HTTP/1.1\r\n" |
| 3873 | "Host: www.example.org\r\n" |
| 3874 | "Connection: keep-alive\r\n\r\n"), |
| 3875 | }; |
| 3876 | |
| 3877 | MockRead data_reads2[] = { |
| 3878 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3879 | |
| 3880 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3881 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3882 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3883 | MockRead(SYNCHRONOUS, "hello"), |
| 3884 | }; |
| 3885 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3886 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3887 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3888 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3889 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3890 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3892 | |
| 3893 | TestCompletionCallback callback; |
| 3894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3895 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3896 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3898 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3899 | ASSERT_TRUE(response); |
| 3900 | ASSERT_TRUE(response->headers); |
| 3901 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3902 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3903 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3905 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3906 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3908 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3909 | ASSERT_TRUE(response); |
| 3910 | ASSERT_TRUE(response->headers); |
| 3911 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3912 | EXPECT_EQ(200, response->headers->response_code()); |
| 3913 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3914 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3915 | EXPECT_EQ("hello", body); |
| 3916 | } |
| 3917 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3918 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3919 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3920 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3921 | HttpRequestInfo request; |
| 3922 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3923 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3924 | request.traffic_annotation = |
| 3925 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3926 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3927 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3928 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3929 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3934 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3935 | // Since we have proxy, should try to establish tunnel. |
| 3936 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3937 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3938 | "Host: www.example.org:443\r\n" |
| 3939 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3940 | }; |
| 3941 | |
| 3942 | // The proxy responds to the connect with a 407. |
| 3943 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3944 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3945 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3946 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3947 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3948 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3949 | }; |
| 3950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3951 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3952 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3954 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3955 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3956 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3958 | |
| 3959 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3963 | ASSERT_TRUE(response); |
| 3964 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3965 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3966 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3967 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3968 | |
| 3969 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3970 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3971 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3972 | |
| 3973 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3974 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3975 | } |
| 3976 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3977 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3978 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3979 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3980 | HttpRequestInfo request; |
| 3981 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3982 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3983 | request.traffic_annotation = |
| 3984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3985 | |
| 3986 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3987 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3988 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3992 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3993 | |
| 3994 | // Since we have proxy, should try to establish tunnel. |
| 3995 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3996 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3997 | "Host: www.example.org:443\r\n" |
| 3998 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3999 | }; |
| 4000 | |
| 4001 | // The proxy responds to the connect with a 407. |
| 4002 | MockRead data_reads[] = { |
| 4003 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4004 | MockRead("X-Foo: bar\r\n"), |
| 4005 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4006 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4007 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4008 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4009 | }; |
| 4010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4011 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4012 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4013 | |
| 4014 | TestCompletionCallback callback; |
| 4015 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4016 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4018 | |
| 4019 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4020 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4022 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4023 | ASSERT_TRUE(response); |
| 4024 | ASSERT_TRUE(response->headers); |
| 4025 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4026 | EXPECT_EQ(407, response->headers->response_code()); |
| 4027 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4028 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4029 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4030 | |
| 4031 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4032 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4033 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4034 | |
| 4035 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4036 | session->CloseAllConnections(); |
| 4037 | } |
| 4038 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4039 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4040 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4041 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4042 | HttpRequestInfo request; |
| 4043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4044 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4045 | request.traffic_annotation = |
| 4046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4047 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4048 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4051 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4052 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4053 | MockWrite( |
| 4054 | "GET / HTTP/1.1\r\n" |
| 4055 | "Host: www.example.org\r\n" |
| 4056 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4057 | }; |
| 4058 | |
| 4059 | MockRead data_reads1[] = { |
| 4060 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4061 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4062 | // Large content-length -- won't matter, as connection will be reset. |
| 4063 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4064 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4065 | }; |
| 4066 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4067 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4070 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4074 | |
| 4075 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4076 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4077 | } |
| 4078 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4079 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4080 | // through a non-authenticating proxy. The request should fail with |
| 4081 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4082 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4083 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4084 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4085 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4086 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4087 | HttpRequestInfo request; |
| 4088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4089 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4090 | request.traffic_annotation = |
| 4091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4092 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4093 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4094 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4095 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4096 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4098 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4099 | // Since we have proxy, should try to establish tunnel. |
| 4100 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4101 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4102 | "Host: www.example.org:443\r\n" |
| 4103 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4104 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4105 | MockWrite("GET / HTTP/1.1\r\n" |
| 4106 | "Host: www.example.org\r\n" |
| 4107 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4108 | }; |
| 4109 | |
| 4110 | MockRead data_reads1[] = { |
| 4111 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4112 | |
| 4113 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4114 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4115 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4116 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4117 | }; |
| 4118 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4119 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4120 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4121 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4124 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4128 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4130 | |
| 4131 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4132 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 4133 | auto entries = log.GetEntries(); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4134 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4135 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4136 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4137 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4138 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4139 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4140 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4141 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4142 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4143 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4144 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4145 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4146 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4147 | HttpRequestInfo request; |
| 4148 | request.method = "GET"; |
| 4149 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4150 | request.traffic_annotation = |
| 4151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4152 | |
| 4153 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4154 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4155 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4156 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4157 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4158 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4159 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4160 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4161 | mock_handler->set_allows_default_credentials(true); |
| 4162 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4163 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4164 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | |
| 4166 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4167 | NetLog net_log; |
| 4168 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4169 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4170 | |
| 4171 | // Since we have proxy, should try to establish tunnel. |
| 4172 | MockWrite data_writes1[] = { |
| 4173 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4174 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4175 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4176 | }; |
| 4177 | |
| 4178 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4179 | // connection. |
| 4180 | MockRead data_reads1[] = { |
| 4181 | // No credentials. |
| 4182 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4183 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4184 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4185 | }; |
| 4186 | |
| 4187 | // Since the first connection couldn't be reused, need to establish another |
| 4188 | // once given credentials. |
| 4189 | MockWrite data_writes2[] = { |
| 4190 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4191 | // be issuing -- the final header line contains the credentials. |
| 4192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4193 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4194 | "Proxy-Connection: keep-alive\r\n" |
| 4195 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4196 | |
| 4197 | MockWrite("GET / HTTP/1.1\r\n" |
| 4198 | "Host: www.example.org\r\n" |
| 4199 | "Connection: keep-alive\r\n\r\n"), |
| 4200 | }; |
| 4201 | |
| 4202 | MockRead data_reads2[] = { |
| 4203 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4204 | |
| 4205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4206 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4207 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4208 | MockRead(SYNCHRONOUS, "hello"), |
| 4209 | }; |
| 4210 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4211 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4213 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4214 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4215 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4217 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4218 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4219 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4220 | |
| 4221 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4222 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | |
| 4225 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4226 | ASSERT_TRUE(response); |
| 4227 | ASSERT_TRUE(response->headers); |
| 4228 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4229 | EXPECT_EQ(407, response->headers->response_code()); |
| 4230 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4231 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4232 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4233 | |
| 4234 | LoadTimingInfo load_timing_info; |
| 4235 | // CONNECT requests and responses are handled at the connect job level, so |
| 4236 | // the transaction does not yet have a connection. |
| 4237 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4238 | |
| 4239 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4240 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4241 | response = trans->GetResponseInfo(); |
| 4242 | ASSERT_TRUE(response); |
| 4243 | ASSERT_TRUE(response->headers); |
| 4244 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4245 | EXPECT_EQ(200, response->headers->response_code()); |
| 4246 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4247 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4248 | |
| 4249 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4250 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4251 | |
| 4252 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4253 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4254 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4255 | |
| 4256 | trans.reset(); |
| 4257 | session->CloseAllConnections(); |
| 4258 | } |
| 4259 | |
| 4260 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4261 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4262 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4263 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4264 | HttpRequestInfo request; |
| 4265 | request.method = "GET"; |
| 4266 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4267 | request.traffic_annotation = |
| 4268 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4269 | |
| 4270 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4271 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4272 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4273 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4274 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4275 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4276 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4277 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4278 | mock_handler->set_allows_default_credentials(true); |
| 4279 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4280 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4281 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4282 | |
| 4283 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4284 | NetLog net_log; |
| 4285 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4286 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4287 | |
| 4288 | // Should try to establish tunnel. |
| 4289 | MockWrite data_writes1[] = { |
| 4290 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4291 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4292 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4293 | |
| 4294 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4295 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4296 | "Proxy-Connection: keep-alive\r\n" |
| 4297 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4298 | }; |
| 4299 | |
| 4300 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4301 | // connection. |
| 4302 | MockRead data_reads1[] = { |
| 4303 | // No credentials. |
| 4304 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4305 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4306 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4307 | }; |
| 4308 | |
| 4309 | // Since the first connection was closed, need to establish another once given |
| 4310 | // credentials. |
| 4311 | MockWrite data_writes2[] = { |
| 4312 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4313 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4314 | "Proxy-Connection: keep-alive\r\n" |
| 4315 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4316 | |
| 4317 | MockWrite("GET / HTTP/1.1\r\n" |
| 4318 | "Host: www.example.org\r\n" |
| 4319 | "Connection: keep-alive\r\n\r\n"), |
| 4320 | }; |
| 4321 | |
| 4322 | MockRead data_reads2[] = { |
| 4323 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4324 | |
| 4325 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4326 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4327 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4328 | MockRead(SYNCHRONOUS, "hello"), |
| 4329 | }; |
| 4330 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4331 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4332 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4333 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4335 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4337 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4338 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4340 | |
| 4341 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4342 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4343 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4344 | |
| 4345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4346 | ASSERT_TRUE(response); |
| 4347 | ASSERT_TRUE(response->headers); |
| 4348 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4349 | EXPECT_EQ(407, response->headers->response_code()); |
| 4350 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4351 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4352 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4353 | |
| 4354 | LoadTimingInfo load_timing_info; |
| 4355 | // CONNECT requests and responses are handled at the connect job level, so |
| 4356 | // the transaction does not yet have a connection. |
| 4357 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4358 | |
| 4359 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4360 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4361 | |
| 4362 | response = trans->GetResponseInfo(); |
| 4363 | ASSERT_TRUE(response); |
| 4364 | ASSERT_TRUE(response->headers); |
| 4365 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4366 | EXPECT_EQ(200, response->headers->response_code()); |
| 4367 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4368 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4369 | |
| 4370 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4371 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4372 | |
| 4373 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4374 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4375 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4376 | |
| 4377 | trans.reset(); |
| 4378 | session->CloseAllConnections(); |
| 4379 | } |
| 4380 | |
| 4381 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4382 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4383 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4384 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4385 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4386 | HttpRequestInfo request; |
| 4387 | request.method = "GET"; |
| 4388 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4389 | request.traffic_annotation = |
| 4390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4391 | |
| 4392 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4393 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4394 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4395 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4396 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4397 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4398 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4399 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4400 | mock_handler->set_allows_default_credentials(true); |
| 4401 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4402 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4403 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4404 | |
| 4405 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4406 | NetLog net_log; |
| 4407 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4408 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4409 | |
| 4410 | // Should try to establish tunnel. |
| 4411 | MockWrite data_writes1[] = { |
| 4412 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4413 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4414 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4415 | |
| 4416 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4417 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4418 | "Proxy-Connection: keep-alive\r\n" |
| 4419 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4420 | }; |
| 4421 | |
| 4422 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4423 | // second request is sent. |
| 4424 | MockRead data_reads1[] = { |
| 4425 | // No credentials. |
| 4426 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4427 | MockRead("Content-Length: 0\r\n"), |
| 4428 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4429 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4430 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4431 | }; |
| 4432 | |
| 4433 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4434 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4435 | // request. |
| 4436 | MockWrite data_writes2[] = { |
| 4437 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4438 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4439 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4440 | }; |
| 4441 | |
| 4442 | // The proxy, having had more than enough of us, just hangs up. |
| 4443 | MockRead data_reads2[] = { |
| 4444 | // No credentials. |
| 4445 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4446 | }; |
| 4447 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4448 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4449 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4450 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4451 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4452 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4453 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4454 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4455 | |
| 4456 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4457 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4458 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4459 | |
| 4460 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4461 | ASSERT_TRUE(response); |
| 4462 | ASSERT_TRUE(response->headers); |
| 4463 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4464 | EXPECT_EQ(407, response->headers->response_code()); |
| 4465 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4466 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4467 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4468 | |
| 4469 | LoadTimingInfo load_timing_info; |
| 4470 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4471 | |
| 4472 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4473 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4474 | |
| 4475 | trans.reset(); |
| 4476 | session->CloseAllConnections(); |
| 4477 | } |
| 4478 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4479 | // This test exercises an odd edge case where the proxy closes the connection |
| 4480 | // after the authentication handshake is complete. Presumably this technique is |
| 4481 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4482 | // succeeds, but the user is not authorized to connect to the destination |
| 4483 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4484 | // site. |
| 4485 | TEST_F(HttpNetworkTransactionTest, |
| 4486 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4487 | HttpRequestInfo request; |
| 4488 | request.method = "GET"; |
| 4489 | request.url = GURL("https://www.example.org/"); |
| 4490 | request.traffic_annotation = |
| 4491 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4492 | |
| 4493 | // Configure against proxy server "myproxy:70". |
| 4494 | session_deps_.proxy_resolution_service = |
| 4495 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4496 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4497 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4498 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4499 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4500 | |
| 4501 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4502 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4503 | // was a real network error. |
| 4504 | // |
| 4505 | // The handlers support both default and explicit credentials. The retry |
| 4506 | // mentioned above should be able to reuse the default identity. Thus there |
| 4507 | // should never be a need to prompt for explicit credentials. |
| 4508 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4509 | mock_handler->set_allows_default_credentials(true); |
| 4510 | mock_handler->set_allows_explicit_credentials(true); |
| 4511 | mock_handler->set_connection_based(true); |
| 4512 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4513 | HttpAuth::AUTH_PROXY); |
| 4514 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4515 | mock_handler->set_allows_default_credentials(true); |
| 4516 | mock_handler->set_allows_explicit_credentials(true); |
| 4517 | mock_handler->set_connection_based(true); |
| 4518 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4519 | HttpAuth::AUTH_PROXY); |
| 4520 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4521 | |
| 4522 | NetLog net_log; |
| 4523 | session_deps_.net_log = &net_log; |
| 4524 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4525 | |
| 4526 | // Data for both sockets. |
| 4527 | // |
| 4528 | // Writes are for the tunnel establishment attempts and the |
| 4529 | // authentication handshake. |
| 4530 | MockWrite data_writes1[] = { |
| 4531 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4532 | "Host: www.example.org:443\r\n" |
| 4533 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4534 | |
| 4535 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4536 | "Host: www.example.org:443\r\n" |
| 4537 | "Proxy-Connection: keep-alive\r\n" |
| 4538 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4539 | |
| 4540 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4541 | "Host: www.example.org:443\r\n" |
| 4542 | "Proxy-Connection: keep-alive\r\n" |
| 4543 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4544 | }; |
| 4545 | |
| 4546 | // The server side of the authentication handshake. Note that the response to |
| 4547 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4548 | MockRead data_reads1[] = { |
| 4549 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4550 | MockRead("Content-Length: 0\r\n"), |
| 4551 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4552 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4553 | |
| 4554 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4555 | MockRead("Content-Length: 0\r\n"), |
| 4556 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4557 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4558 | |
| 4559 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4560 | }; |
| 4561 | |
| 4562 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4563 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4564 | |
| 4565 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4566 | // first attempt. |
| 4567 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4568 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4569 | |
| 4570 | auto trans = |
| 4571 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4572 | |
| 4573 | TestCompletionCallback callback; |
| 4574 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4575 | |
| 4576 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4577 | // stack. |
| 4578 | for (int i = 0; i < 4; ++i) { |
| 4579 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4580 | |
| 4581 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4582 | ASSERT_TRUE(response); |
| 4583 | ASSERT_TRUE(response->headers); |
| 4584 | EXPECT_EQ(407, response->headers->response_code()); |
| 4585 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4586 | |
| 4587 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4588 | } |
| 4589 | |
| 4590 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4591 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4592 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4593 | // being the first number, be reached, then lobbest thou thy |
| 4594 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4595 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4596 | |
| 4597 | trans.reset(); |
| 4598 | session->CloseAllConnections(); |
| 4599 | } |
| 4600 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4601 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4602 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4603 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4604 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4605 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4606 | HttpRequestInfo request; |
| 4607 | request.method = "GET"; |
| 4608 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4609 | request.traffic_annotation = |
| 4610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4611 | |
| 4612 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4613 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4614 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4615 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4616 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4617 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4618 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4619 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4620 | mock_handler->set_allows_default_credentials(true); |
| 4621 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4622 | HttpAuth::AUTH_PROXY); |
| 4623 | // Add another handler for the second challenge. It supports default |
| 4624 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4625 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4626 | mock_handler->set_allows_default_credentials(true); |
| 4627 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4628 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4629 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4630 | |
| 4631 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4632 | NetLog net_log; |
| 4633 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4634 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4635 | |
| 4636 | // Should try to establish tunnel. |
| 4637 | MockWrite data_writes1[] = { |
| 4638 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4639 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4640 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4641 | }; |
| 4642 | |
| 4643 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4644 | // connection. |
| 4645 | MockRead data_reads1[] = { |
| 4646 | // No credentials. |
| 4647 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4648 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4649 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4650 | }; |
| 4651 | |
| 4652 | // Since the first connection was closed, need to establish another once given |
| 4653 | // credentials. |
| 4654 | MockWrite data_writes2[] = { |
| 4655 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4656 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4657 | "Proxy-Connection: keep-alive\r\n" |
| 4658 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4659 | }; |
| 4660 | |
| 4661 | MockRead data_reads2[] = { |
| 4662 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4663 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4664 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4665 | }; |
| 4666 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4667 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4669 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4670 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4671 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4673 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4674 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4675 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4676 | |
| 4677 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4678 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4679 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4680 | |
| 4681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4682 | ASSERT_TRUE(response); |
| 4683 | ASSERT_TRUE(response->headers); |
| 4684 | EXPECT_EQ(407, response->headers->response_code()); |
| 4685 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4686 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4687 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4688 | |
| 4689 | LoadTimingInfo load_timing_info; |
| 4690 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4691 | |
| 4692 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4693 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4694 | response = trans->GetResponseInfo(); |
| 4695 | ASSERT_TRUE(response); |
| 4696 | ASSERT_TRUE(response->headers); |
| 4697 | EXPECT_EQ(407, response->headers->response_code()); |
| 4698 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4699 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4700 | |
| 4701 | trans.reset(); |
| 4702 | session->CloseAllConnections(); |
| 4703 | } |
| 4704 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4705 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4706 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4707 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4708 | // authentication handshake can continue with the same scheme but with a |
| 4709 | // different identity. |
| 4710 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4711 | HttpRequestInfo request; |
| 4712 | request.method = "GET"; |
| 4713 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4714 | request.traffic_annotation = |
| 4715 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4716 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4717 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4718 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4719 | |
| 4720 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4721 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4722 | mock_handler->set_allows_default_credentials(true); |
| 4723 | mock_handler->set_allows_explicit_credentials(true); |
| 4724 | mock_handler->set_connection_based(true); |
| 4725 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4726 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4727 | HttpAuth::AUTH_SERVER); |
| 4728 | |
| 4729 | // Add another handler for the second challenge. It supports default |
| 4730 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4731 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4732 | mock_handler->set_allows_default_credentials(true); |
| 4733 | mock_handler->set_allows_explicit_credentials(true); |
| 4734 | mock_handler->set_connection_based(true); |
| 4735 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4736 | HttpAuth::AUTH_SERVER); |
| 4737 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4738 | |
| 4739 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4740 | |
| 4741 | MockWrite data_writes1[] = { |
| 4742 | MockWrite("GET / HTTP/1.1\r\n" |
| 4743 | "Host: www.example.org\r\n" |
| 4744 | "Connection: keep-alive\r\n\r\n"), |
| 4745 | }; |
| 4746 | |
| 4747 | MockRead data_reads1[] = { |
| 4748 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4749 | "WWW-Authenticate: Mock\r\n" |
| 4750 | "Connection: keep-alive\r\n\r\n"), |
| 4751 | }; |
| 4752 | |
| 4753 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4754 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4755 | // transaction procceds without an authorization header. |
| 4756 | MockWrite data_writes2[] = { |
| 4757 | MockWrite("GET / HTTP/1.1\r\n" |
| 4758 | "Host: www.example.org\r\n" |
| 4759 | "Connection: keep-alive\r\n\r\n"), |
| 4760 | }; |
| 4761 | |
| 4762 | MockRead data_reads2[] = { |
| 4763 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4764 | "WWW-Authenticate: Mock\r\n" |
| 4765 | "Connection: keep-alive\r\n\r\n"), |
| 4766 | }; |
| 4767 | |
| 4768 | MockWrite data_writes3[] = { |
| 4769 | MockWrite("GET / HTTP/1.1\r\n" |
| 4770 | "Host: www.example.org\r\n" |
| 4771 | "Connection: keep-alive\r\n" |
| 4772 | "Authorization: auth_token\r\n\r\n"), |
| 4773 | }; |
| 4774 | |
| 4775 | MockRead data_reads3[] = { |
| 4776 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4777 | "Content-Length: 5\r\n" |
| 4778 | "Content-Type: text/plain\r\n" |
| 4779 | "Connection: keep-alive\r\n\r\n" |
| 4780 | "Hello"), |
| 4781 | }; |
| 4782 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4783 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4784 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4785 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4786 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4787 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4788 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4789 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4790 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4791 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4792 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4793 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4794 | |
| 4795 | TestCompletionCallback callback; |
| 4796 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4797 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4798 | |
| 4799 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4800 | ASSERT_TRUE(response); |
| 4801 | ASSERT_TRUE(response->headers); |
| 4802 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4803 | |
| 4804 | // The following three tests assert that an authentication challenge was |
| 4805 | // received and that the stack is ready to respond to the challenge using |
| 4806 | // ambient credentials. |
| 4807 | EXPECT_EQ(401, response->headers->response_code()); |
| 4808 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4809 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4810 | |
| 4811 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4812 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4813 | response = trans->GetResponseInfo(); |
| 4814 | ASSERT_TRUE(response); |
| 4815 | ASSERT_TRUE(response->headers); |
| 4816 | |
| 4817 | // The following three tests assert that an authentication challenge was |
| 4818 | // received and that the stack needs explicit credentials before it is ready |
| 4819 | // to respond to the challenge. |
| 4820 | EXPECT_EQ(401, response->headers->response_code()); |
| 4821 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4822 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4823 | |
| 4824 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4825 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4826 | response = trans->GetResponseInfo(); |
| 4827 | ASSERT_TRUE(response); |
| 4828 | ASSERT_TRUE(response->headers); |
| 4829 | EXPECT_EQ(200, response->headers->response_code()); |
| 4830 | |
| 4831 | trans.reset(); |
| 4832 | session->CloseAllConnections(); |
| 4833 | } |
| 4834 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4835 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4836 | // schemes, based on the path of the URL being requests. |
| 4837 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4838 | public: |
| 4839 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4840 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4841 | |
| 4842 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4843 | |
| 4844 | static HostPortPair ProxyHostPortPair() { |
| 4845 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4846 | } |
| 4847 | |
| 4848 | // ProxyResolver implementation. |
| 4849 | int GetProxyForURL(const GURL& url, |
| 4850 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4851 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4852 | std::unique_ptr<Request>* request, |
| 4853 | const NetLogWithSource& /*net_log*/) override { |
| 4854 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4855 | results->set_traffic_annotation( |
| 4856 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4857 | if (url.path() == "/socks4") { |
| 4858 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4859 | return OK; |
| 4860 | } |
| 4861 | if (url.path() == "/socks5") { |
| 4862 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4863 | return OK; |
| 4864 | } |
| 4865 | if (url.path() == "/http") { |
| 4866 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4867 | return OK; |
| 4868 | } |
| 4869 | if (url.path() == "/https") { |
| 4870 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4871 | return OK; |
| 4872 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4873 | if (url.path() == "/https_trusted") { |
| 4874 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4875 | ProxyHostPortPair(), |
| 4876 | true /* is_trusted_proxy */)); |
| 4877 | return OK; |
| 4878 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4879 | NOTREACHED(); |
| 4880 | return ERR_NOT_IMPLEMENTED; |
| 4881 | } |
| 4882 | |
| 4883 | private: |
| 4884 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4885 | }; |
| 4886 | |
| 4887 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4888 | : public ProxyResolverFactory { |
| 4889 | public: |
| 4890 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4891 | : ProxyResolverFactory(false) {} |
| 4892 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4893 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4894 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4895 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4896 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4897 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4898 | return OK; |
| 4899 | } |
| 4900 | |
| 4901 | private: |
| 4902 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4903 | }; |
| 4904 | |
| 4905 | // 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] | 4906 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4907 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4908 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4909 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4910 | session_deps_.proxy_resolution_service = |
| 4911 | std::make_unique<ProxyResolutionService>( |
| 4912 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4913 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4914 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4915 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4916 | |
| 4917 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4918 | |
| 4919 | MockWrite socks_writes[] = { |
| 4920 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4921 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4922 | MockWrite(SYNCHRONOUS, |
| 4923 | "GET /socks4 HTTP/1.1\r\n" |
| 4924 | "Host: test\r\n" |
| 4925 | "Connection: keep-alive\r\n\r\n"), |
| 4926 | }; |
| 4927 | MockRead socks_reads[] = { |
| 4928 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4929 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4930 | "Connection: keep-alive\r\n" |
| 4931 | "Content-Length: 15\r\n\r\n" |
| 4932 | "SOCKS4 Response"), |
| 4933 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4934 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4935 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4936 | |
| 4937 | const char kSOCKS5Request[] = { |
| 4938 | 0x05, // Version |
| 4939 | 0x01, // Command (CONNECT) |
| 4940 | 0x00, // Reserved |
| 4941 | 0x03, // Address type (DOMAINNAME) |
| 4942 | 0x04, // Length of domain (4) |
| 4943 | 't', 'e', 's', 't', // Domain string |
| 4944 | 0x00, 0x50, // 16-bit port (80) |
| 4945 | }; |
| 4946 | MockWrite socks5_writes[] = { |
| 4947 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4948 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4949 | MockWrite(SYNCHRONOUS, |
| 4950 | "GET /socks5 HTTP/1.1\r\n" |
| 4951 | "Host: test\r\n" |
| 4952 | "Connection: keep-alive\r\n\r\n"), |
| 4953 | }; |
| 4954 | MockRead socks5_reads[] = { |
| 4955 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4956 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4957 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4958 | "Connection: keep-alive\r\n" |
| 4959 | "Content-Length: 15\r\n\r\n" |
| 4960 | "SOCKS5 Response"), |
| 4961 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4962 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4963 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4964 | |
| 4965 | MockWrite http_writes[] = { |
| 4966 | MockWrite(SYNCHRONOUS, |
| 4967 | "GET http://test/http HTTP/1.1\r\n" |
| 4968 | "Host: test\r\n" |
| 4969 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4970 | }; |
| 4971 | MockRead http_reads[] = { |
| 4972 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4973 | "Proxy-Connection: keep-alive\r\n" |
| 4974 | "Content-Length: 13\r\n\r\n" |
| 4975 | "HTTP Response"), |
| 4976 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4977 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4978 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4979 | |
| 4980 | MockWrite https_writes[] = { |
| 4981 | MockWrite(SYNCHRONOUS, |
| 4982 | "GET http://test/https HTTP/1.1\r\n" |
| 4983 | "Host: test\r\n" |
| 4984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4985 | }; |
| 4986 | MockRead https_reads[] = { |
| 4987 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4988 | "Proxy-Connection: keep-alive\r\n" |
| 4989 | "Content-Length: 14\r\n\r\n" |
| 4990 | "HTTPS Response"), |
| 4991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4992 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4993 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4994 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4996 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4997 | MockWrite https_trusted_writes[] = { |
| 4998 | MockWrite(SYNCHRONOUS, |
| 4999 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5000 | "Host: test\r\n" |
| 5001 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5002 | }; |
| 5003 | MockRead https_trusted_reads[] = { |
| 5004 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5005 | "Proxy-Connection: keep-alive\r\n" |
| 5006 | "Content-Length: 22\r\n\r\n" |
| 5007 | "HTTPS Trusted Response"), |
| 5008 | }; |
| 5009 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5010 | https_trusted_writes); |
| 5011 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5012 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5013 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5014 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5015 | struct TestCase { |
| 5016 | GURL url; |
| 5017 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5018 | // 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] | 5019 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5020 | int expected_idle_socks4_sockets; |
| 5021 | int expected_idle_socks5_sockets; |
| 5022 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5023 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5024 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5025 | int expected_idle_https_sockets; |
| 5026 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5027 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5028 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5029 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5030 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5031 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5032 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5033 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5034 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5035 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5036 | }; |
| 5037 | |
| 5038 | for (const auto& test_case : kTestCases) { |
| 5039 | HttpRequestInfo request; |
| 5040 | request.method = "GET"; |
| 5041 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5042 | request.traffic_annotation = |
| 5043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5044 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5045 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5046 | session.get()); |
| 5047 | TestCompletionCallback callback; |
| 5048 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5049 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5050 | |
| 5051 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5052 | ASSERT_TRUE(response); |
| 5053 | ASSERT_TRUE(response->headers); |
| 5054 | EXPECT_EQ(200, response->headers->response_code()); |
| 5055 | std::string response_data; |
| 5056 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5057 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5058 | |
| 5059 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5060 | // the next requests. |
| 5061 | trans.reset(); |
| 5062 | base::RunLoop().RunUntilIdle(); |
| 5063 | |
| 5064 | // Check the number of idle sockets in the pool, to make sure that used |
| 5065 | // sockets are indeed being returned to the socket pool. If each request |
| 5066 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5067 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5068 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5069 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5070 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5071 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5072 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5073 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5074 | ProxyHostPortPair())) |
| 5075 | ->IdleSocketCount()); |
| 5076 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5077 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5078 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5079 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5080 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5081 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5082 | ProxyHostPortPair())) |
| 5083 | ->IdleSocketCount()); |
| 5084 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5085 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5086 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5087 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5088 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5089 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5090 | ProxyHostPortPair())) |
| 5091 | ->IdleSocketCount()); |
| 5092 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5093 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5094 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5095 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5096 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5097 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5098 | ProxyHostPortPair())) |
| 5099 | ->IdleSocketCount()); |
| 5100 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5101 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5102 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5103 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5104 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5105 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5106 | ProxyHostPortPair(), |
| 5107 | true /* is_trusted_proxy */)) |
| 5108 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5109 | } |
| 5110 | } |
| 5111 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5112 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5113 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5114 | HttpRequestInfo request1; |
| 5115 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5116 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5117 | request1.traffic_annotation = |
| 5118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5119 | |
| 5120 | HttpRequestInfo request2; |
| 5121 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5122 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5123 | request2.traffic_annotation = |
| 5124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5125 | |
| 5126 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5127 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5128 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5129 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5130 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5132 | |
| 5133 | // Since we have proxy, should try to establish tunnel. |
| 5134 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5135 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5136 | "Host: www.example.org:443\r\n" |
| 5137 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5138 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5139 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5140 | "Host: www.example.org\r\n" |
| 5141 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5142 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5143 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5144 | "Host: www.example.org\r\n" |
| 5145 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5146 | }; |
| 5147 | |
| 5148 | // The proxy responds to the connect with a 407, using a persistent |
| 5149 | // connection. |
| 5150 | MockRead data_reads1[] = { |
| 5151 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5152 | |
| 5153 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5154 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5155 | MockRead(SYNCHRONOUS, "1"), |
| 5156 | |
| 5157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5158 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5159 | MockRead(SYNCHRONOUS, "22"), |
| 5160 | }; |
| 5161 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5162 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5163 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5164 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5166 | |
| 5167 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5168 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5169 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5170 | |
| 5171 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5173 | |
| 5174 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5175 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5176 | |
| 5177 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5178 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5179 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5180 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5181 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5182 | |
| 5183 | LoadTimingInfo load_timing_info1; |
| 5184 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5185 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5186 | |
| 5187 | trans1.reset(); |
| 5188 | |
| 5189 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5190 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5191 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5192 | |
| 5193 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5195 | |
| 5196 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5197 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5198 | |
| 5199 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5200 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5201 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5202 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5203 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5204 | |
| 5205 | LoadTimingInfo load_timing_info2; |
| 5206 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5207 | TestLoadTimingReused(load_timing_info2); |
| 5208 | |
| 5209 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5210 | |
| 5211 | trans2.reset(); |
| 5212 | session->CloseAllConnections(); |
| 5213 | } |
| 5214 | |
| 5215 | // 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] | 5216 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5217 | HttpRequestInfo request1; |
| 5218 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5219 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5220 | request1.traffic_annotation = |
| 5221 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5222 | |
| 5223 | HttpRequestInfo request2; |
| 5224 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5225 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5226 | request2.traffic_annotation = |
| 5227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | |
| 5229 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5230 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5231 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5232 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5233 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5234 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5235 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5236 | |
| 5237 | // Since we have proxy, should try to establish tunnel. |
| 5238 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5239 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5240 | "Host: www.example.org:443\r\n" |
| 5241 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5242 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5243 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5244 | "Host: www.example.org\r\n" |
| 5245 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5246 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5247 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5248 | "Host: www.example.org\r\n" |
| 5249 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5250 | }; |
| 5251 | |
| 5252 | // The proxy responds to the connect with a 407, using a persistent |
| 5253 | // connection. |
| 5254 | MockRead data_reads1[] = { |
| 5255 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5256 | |
| 5257 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5258 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5259 | MockRead(SYNCHRONOUS, "1"), |
| 5260 | |
| 5261 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5262 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5263 | MockRead(SYNCHRONOUS, "22"), |
| 5264 | }; |
| 5265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5266 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5267 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5268 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5270 | |
| 5271 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5272 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5273 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5274 | |
| 5275 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5277 | |
| 5278 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5279 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5280 | |
| 5281 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5282 | ASSERT_TRUE(response1); |
| 5283 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5284 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5285 | |
| 5286 | LoadTimingInfo load_timing_info1; |
| 5287 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5288 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5289 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5290 | |
| 5291 | trans1.reset(); |
| 5292 | |
| 5293 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5294 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5295 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5296 | |
| 5297 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5299 | |
| 5300 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5302 | |
| 5303 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5304 | ASSERT_TRUE(response2); |
| 5305 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5306 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5307 | |
| 5308 | LoadTimingInfo load_timing_info2; |
| 5309 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5310 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5311 | |
| 5312 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5313 | |
| 5314 | trans2.reset(); |
| 5315 | session->CloseAllConnections(); |
| 5316 | } |
| 5317 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5318 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5319 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5320 | HttpRequestInfo request; |
| 5321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5322 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5323 | request.traffic_annotation = |
| 5324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5325 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5326 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5327 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5328 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5329 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5330 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5332 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5333 | // Since we have proxy, should use full url |
| 5334 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5335 | MockWrite( |
| 5336 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5337 | "Host: www.example.org\r\n" |
| 5338 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5339 | }; |
| 5340 | |
| 5341 | MockRead data_reads1[] = { |
| 5342 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5343 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5344 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5345 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5346 | }; |
| 5347 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5348 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5349 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5350 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5353 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5354 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5355 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5357 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5359 | |
| 5360 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5361 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5362 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5363 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5364 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5365 | TestLoadTimingNotReused(load_timing_info, |
| 5366 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5369 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5370 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5371 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5372 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5373 | EXPECT_EQ(200, response->headers->response_code()); |
| 5374 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5375 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5376 | |
| 5377 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5378 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5379 | } |
| 5380 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5381 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5382 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5383 | HttpRequestInfo request; |
| 5384 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5385 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5386 | request.traffic_annotation = |
| 5387 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5388 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5389 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5390 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5391 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5392 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5393 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5395 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5396 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5397 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5398 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5399 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5400 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5401 | spdy::SpdySerializedFrame resp( |
| 5402 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5403 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5404 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5405 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5406 | }; |
| 5407 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5408 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5409 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5410 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5411 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5412 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5413 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5415 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5419 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5421 | |
| 5422 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5424 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5425 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5426 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5427 | TestLoadTimingNotReused(load_timing_info, |
| 5428 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5429 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5430 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5431 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5432 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5433 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5434 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5435 | |
| 5436 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5437 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5438 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5439 | } |
| 5440 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5441 | // Verifies that a session which races and wins against the owning transaction |
| 5442 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5443 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5444 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5445 | HttpRequestInfo request; |
| 5446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5447 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5448 | request.traffic_annotation = |
| 5449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5450 | |
| 5451 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5452 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5453 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5454 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5455 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5457 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5458 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5459 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5460 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5461 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5462 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5463 | spdy::SpdySerializedFrame resp( |
| 5464 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5465 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5466 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5467 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5468 | }; |
| 5469 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5470 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5471 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5472 | |
| 5473 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5474 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5476 | |
| 5477 | TestCompletionCallback callback1; |
| 5478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5480 | |
| 5481 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5482 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5484 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5486 | |
| 5487 | // Race a session to the proxy, which completes first. |
| 5488 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5489 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5490 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 5491 | SpdySessionKey::IsProxySession::kTrue, SocketTag(), |
| 5492 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5493 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5494 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5495 | |
| 5496 | // Unstall the resolution begun by the transaction. |
| 5497 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5498 | session_deps_.host_resolver->ResolveAllPending(); |
| 5499 | |
| 5500 | EXPECT_FALSE(callback1.have_result()); |
| 5501 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5502 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5504 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5505 | ASSERT_TRUE(response); |
| 5506 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5507 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5508 | |
| 5509 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5510 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5511 | EXPECT_EQ(kUploadData, response_data); |
| 5512 | } |
| 5513 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5514 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5515 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5516 | HttpRequestInfo request; |
| 5517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5518 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5519 | request.traffic_annotation = |
| 5520 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5521 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5522 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5523 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5524 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5525 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5526 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5528 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5529 | // The first request will be a bare GET, the second request will be a |
| 5530 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5531 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5532 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5533 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5534 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5535 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5536 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5537 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5538 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5539 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5540 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5541 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5542 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5543 | }; |
| 5544 | |
| 5545 | // The first response is a 407 proxy authentication challenge, and the second |
| 5546 | // response will be a 200 response since the second request includes a valid |
| 5547 | // Authorization header. |
| 5548 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5549 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5550 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5551 | spdy::SpdySerializedFrame resp_authentication( |
| 5552 | spdy_util_.ConstructSpdyReplyError( |
| 5553 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5554 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5555 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5556 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5557 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5558 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5559 | spdy::SpdySerializedFrame body_data( |
| 5560 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5561 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5562 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5563 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5564 | CreateMockRead(resp_data, 4), |
| 5565 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5566 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5567 | }; |
| 5568 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5569 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5571 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5572 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5573 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5576 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5578 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5580 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5582 | |
| 5583 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5584 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5586 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5587 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5588 | ASSERT_TRUE(response); |
| 5589 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5590 | EXPECT_EQ(407, response->headers->response_code()); |
| 5591 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5592 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5593 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5594 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5596 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5598 | |
| 5599 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5600 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5602 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5603 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5604 | ASSERT_TRUE(response_restart); |
| 5605 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5606 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5607 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5608 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5609 | } |
| 5610 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5611 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5612 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5613 | HttpRequestInfo request; |
| 5614 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5615 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5616 | request.traffic_annotation = |
| 5617 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5618 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5619 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5620 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5621 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5622 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5623 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5627 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5628 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5629 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5630 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5631 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5632 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5633 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5634 | const char get[] = |
| 5635 | "GET / HTTP/1.1\r\n" |
| 5636 | "Host: www.example.org\r\n" |
| 5637 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5638 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5639 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5640 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5641 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5642 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5643 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5644 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5645 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5646 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5647 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5648 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5649 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5650 | |
| 5651 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5652 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5653 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5654 | }; |
| 5655 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5656 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5657 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5658 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5659 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5660 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5661 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5662 | }; |
| 5663 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5664 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5665 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5666 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5667 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5668 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5669 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5670 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5671 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5673 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5675 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5677 | |
| 5678 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5679 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5680 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5681 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5682 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5683 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5686 | ASSERT_TRUE(response); |
| 5687 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5688 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5689 | |
| 5690 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5691 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5692 | EXPECT_EQ("1234567890", response_data); |
| 5693 | } |
| 5694 | |
| 5695 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5696 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5697 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5698 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5699 | HttpRequestInfo request; |
| 5700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5701 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5702 | request.traffic_annotation = |
| 5703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5704 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5705 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5706 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5707 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5708 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5709 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5710 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5713 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5714 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5715 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5716 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5717 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5718 | // fetch https://www.example.org/ via SPDY |
| 5719 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5720 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5721 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5722 | spdy::SpdySerializedFrame wrapped_get( |
| 5723 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5724 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5725 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5726 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5727 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5728 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5729 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5730 | spdy::SpdySerializedFrame body( |
| 5731 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5732 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5733 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5734 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5735 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5736 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5737 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5738 | |
| 5739 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5740 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5741 | CreateMockWrite(window_update_get_resp, 6), |
| 5742 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5743 | }; |
| 5744 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5745 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5746 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5747 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5748 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5749 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5750 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5751 | }; |
| 5752 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5753 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5754 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5755 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5756 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5757 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5758 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5759 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5760 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5763 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5765 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5767 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5768 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5769 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5770 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5771 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5772 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5773 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5774 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5775 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5776 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5777 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5779 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5780 | ASSERT_TRUE(response); |
| 5781 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5782 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5783 | |
| 5784 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5785 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5786 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5790 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5791 | HttpRequestInfo request; |
| 5792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5793 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5794 | request.traffic_annotation = |
| 5795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5796 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5797 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5798 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5799 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5800 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5801 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5805 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5806 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5807 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5808 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5809 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5810 | spdy::SpdySerializedFrame get( |
| 5811 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5812 | |
| 5813 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5814 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5815 | }; |
| 5816 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5817 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5818 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5820 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5821 | }; |
| 5822 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5823 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5824 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5825 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5826 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5827 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5829 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5830 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5833 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5835 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5837 | |
| 5838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5839 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5840 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5841 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5842 | } |
| 5843 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5844 | // 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] | 5845 | // is observed, but does exist by the time auth credentials are provided. In |
| 5846 | // this case, auth and SSL are fully negotated on the second request, but then |
| 5847 | // the socket is discarded to use the shared session. |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5848 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5849 | ProxyConfig proxy_config; |
| 5850 | proxy_config.set_auto_detect(true); |
| 5851 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5852 | |
| 5853 | CapturingProxyResolver capturing_proxy_resolver; |
| 5854 | capturing_proxy_resolver.set_proxy_server( |
| 5855 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5856 | session_deps_.proxy_resolution_service = |
| 5857 | std::make_unique<ProxyResolutionService>( |
| 5858 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5859 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5860 | std::make_unique<CapturingProxyResolverFactory>( |
| 5861 | &capturing_proxy_resolver), |
| 5862 | nullptr); |
| 5863 | |
| 5864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5865 | |
| 5866 | const char kMyUrl[] = "https://www.example.org/"; |
| 5867 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5868 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5869 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5870 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5871 | |
| 5872 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5873 | spdy::SpdySerializedFrame get2( |
| 5874 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5875 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5876 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5877 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5878 | |
| 5879 | MockWrite auth_challenge_writes[] = { |
| 5880 | MockWrite(ASYNC, 0, |
| 5881 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5882 | "Host: www.example.org:443\r\n" |
| 5883 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 5884 | MockWrite(ASYNC, 2, |
| 5885 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5886 | "Host: www.example.org:443\r\n" |
| 5887 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5888 | }; |
| 5889 | |
| 5890 | MockRead auth_challenge_reads[] = { |
| 5891 | MockRead(ASYNC, 1, |
| 5892 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5893 | "Content-Length: 0\r\n" |
| 5894 | "Proxy-Connection: close\r\n" |
| 5895 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5896 | }; |
| 5897 | |
| 5898 | MockWrite spdy_writes[] = { |
| 5899 | MockWrite(ASYNC, 0, |
| 5900 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5901 | "Host: www.example.org:443\r\n" |
| 5902 | "Proxy-Connection: keep-alive\r\n" |
| 5903 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5904 | CreateMockWrite(get, 2), |
| 5905 | CreateMockWrite(get2, 5), |
| 5906 | }; |
| 5907 | |
| 5908 | MockRead spdy_reads[] = { |
| 5909 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5910 | CreateMockRead(get_resp, 3, ASYNC), |
| 5911 | CreateMockRead(body, 4, ASYNC), |
| 5912 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5913 | CreateMockRead(body2, 7, ASYNC), |
| 5914 | |
| 5915 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5916 | }; |
| 5917 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 5918 | MockWrite auth_response_writes_discarded_socket[] = { |
| 5919 | MockWrite(ASYNC, 0, |
| 5920 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5921 | "Host: www.example.org:443\r\n" |
| 5922 | "Proxy-Connection: keep-alive\r\n" |
| 5923 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5924 | }; |
| 5925 | |
| 5926 | MockRead auth_response_reads_discarded_socket[] = { |
| 5927 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5928 | }; |
| 5929 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5930 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5931 | auth_challenge_writes); |
| 5932 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5933 | |
| 5934 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5935 | auth_challenge_writes); |
| 5936 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5937 | |
| 5938 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5939 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5940 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 5941 | SequencedSocketData auth_response_discarded_socket( |
| 5942 | auth_response_reads_discarded_socket, |
| 5943 | auth_response_writes_discarded_socket); |
| 5944 | session_deps_.socket_factory->AddSocketDataProvider( |
| 5945 | &auth_response_discarded_socket); |
| 5946 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5947 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5948 | ssl.next_proto = kProtoHTTP2; |
| 5949 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5950 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 5951 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 5952 | ssl2.next_proto = kProtoHTTP2; |
| 5953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5954 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5955 | TestCompletionCallback callback; |
| 5956 | std::string response_data; |
| 5957 | |
| 5958 | // Run first request until an auth challenge is observed. |
| 5959 | HttpRequestInfo request1; |
| 5960 | request1.method = "GET"; |
| 5961 | request1.url = GURL(kMyUrl); |
| 5962 | request1.traffic_annotation = |
| 5963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5964 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5965 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5966 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5967 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5968 | ASSERT_TRUE(response); |
| 5969 | ASSERT_TRUE(response->headers); |
| 5970 | EXPECT_EQ(407, response->headers->response_code()); |
| 5971 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5972 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5973 | |
| 5974 | // Run second request until an auth challenge is observed. |
| 5975 | HttpRequestInfo request2; |
| 5976 | request2.method = "GET"; |
| 5977 | request2.url = GURL(kMyUrl); |
| 5978 | request2.traffic_annotation = |
| 5979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5980 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 5981 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 5982 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5983 | response = trans2.GetResponseInfo(); |
| 5984 | ASSERT_TRUE(response); |
| 5985 | ASSERT_TRUE(response->headers); |
| 5986 | EXPECT_EQ(407, response->headers->response_code()); |
| 5987 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5988 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5989 | |
| 5990 | // Now provide credentials for the first request, and wait for it to complete. |
| 5991 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 5992 | rv = callback.GetResult(rv); |
| 5993 | EXPECT_THAT(rv, IsOk()); |
| 5994 | response = trans1.GetResponseInfo(); |
| 5995 | ASSERT_TRUE(response); |
| 5996 | ASSERT_TRUE(response->headers); |
| 5997 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 5998 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 5999 | EXPECT_EQ(kUploadData, response_data); |
| 6000 | |
| 6001 | // Now provide credentials for the second request. It should notice the |
| 6002 | // existing session, and reuse it. |
| 6003 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6004 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6005 | response = trans2.GetResponseInfo(); |
| 6006 | ASSERT_TRUE(response); |
| 6007 | ASSERT_TRUE(response->headers); |
| 6008 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6009 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6010 | EXPECT_EQ(kUploadData, response_data); |
| 6011 | } |
| 6012 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6013 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6014 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6015 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6016 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6017 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6018 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6019 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6020 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6021 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6022 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6023 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6024 | |
| 6025 | HttpRequestInfo request1; |
| 6026 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6027 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6028 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6029 | request1.traffic_annotation = |
| 6030 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6031 | |
| 6032 | HttpRequestInfo request2; |
| 6033 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6034 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6035 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6036 | request2.traffic_annotation = |
| 6037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6038 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6039 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6040 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6041 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6042 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6043 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6044 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6045 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6046 | // Fetch https://www.example.org/ via HTTP. |
| 6047 | const char get1[] = |
| 6048 | "GET / HTTP/1.1\r\n" |
| 6049 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6050 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6051 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6052 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6053 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6054 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6055 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6056 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6057 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6058 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6059 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6060 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6061 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6062 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6063 | spdy::SpdyHeaderBlock connect2_block; |
| 6064 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6065 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6066 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6067 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6068 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6069 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6070 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6071 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6072 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6073 | // Fetch https://mail.example.org/ via HTTP. |
| 6074 | const char get2[] = |
| 6075 | "GET / HTTP/1.1\r\n" |
| 6076 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6077 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6078 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6079 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6080 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6081 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6082 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6083 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6084 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6085 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6086 | |
| 6087 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6088 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6089 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6090 | }; |
| 6091 | |
| 6092 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6093 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6094 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6095 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6096 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6097 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6098 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6099 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6100 | }; |
| 6101 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6102 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6103 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6104 | |
| 6105 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6106 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6107 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6108 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6110 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6112 | |
| 6113 | TestCompletionCallback callback; |
| 6114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6116 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6117 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6118 | |
| 6119 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6120 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6121 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6124 | ASSERT_TRUE(response); |
| 6125 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6127 | |
| 6128 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6129 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6130 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6131 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6133 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6134 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6135 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6136 | |
| 6137 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6138 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6139 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6140 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6141 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6142 | |
| 6143 | // The requests should have different IDs, since they each are using their own |
| 6144 | // separate stream. |
| 6145 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6147 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6148 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6149 | } |
| 6150 | |
| 6151 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6152 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6153 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6154 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6155 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6156 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6157 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6158 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6159 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6160 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6161 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6162 | |
| 6163 | HttpRequestInfo request1; |
| 6164 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6165 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6166 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6167 | request1.traffic_annotation = |
| 6168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6169 | |
| 6170 | HttpRequestInfo request2; |
| 6171 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6172 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6173 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6174 | request2.traffic_annotation = |
| 6175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6176 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6177 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6178 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6179 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6180 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6181 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6182 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6183 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6184 | // Fetch https://www.example.org/ via HTTP. |
| 6185 | const char get1[] = |
| 6186 | "GET / HTTP/1.1\r\n" |
| 6187 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6188 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6189 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6190 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6191 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6192 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6193 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6194 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6195 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6196 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6197 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6198 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6199 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | // Fetch https://www.example.org/2 via HTTP. |
| 6201 | const char get2[] = |
| 6202 | "GET /2 HTTP/1.1\r\n" |
| 6203 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6205 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6206 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6207 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6208 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6209 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6210 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6211 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6212 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6213 | |
| 6214 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6215 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6216 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6217 | }; |
| 6218 | |
| 6219 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6220 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6221 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6222 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6223 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6224 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6225 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6226 | }; |
| 6227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6228 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6229 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6230 | |
| 6231 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6232 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6234 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6235 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6236 | |
| 6237 | TestCompletionCallback callback; |
| 6238 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6239 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6240 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6241 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6243 | |
| 6244 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6246 | |
| 6247 | LoadTimingInfo load_timing_info; |
| 6248 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6249 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6250 | |
| 6251 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6252 | ASSERT_TRUE(response); |
| 6253 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6254 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6255 | |
| 6256 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6257 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6258 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6259 | trans.reset(); |
| 6260 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6261 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6262 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6263 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6265 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6266 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | |
| 6269 | LoadTimingInfo load_timing_info2; |
| 6270 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6271 | TestLoadTimingReused(load_timing_info2); |
| 6272 | |
| 6273 | // The requests should have the same ID. |
| 6274 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6275 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6276 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6280 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6281 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6282 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6283 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6284 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6285 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6286 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6287 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6288 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6289 | |
| 6290 | HttpRequestInfo request1; |
| 6291 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6292 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6293 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6294 | request1.traffic_annotation = |
| 6295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6296 | |
| 6297 | HttpRequestInfo request2; |
| 6298 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6299 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6300 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6301 | request2.traffic_annotation = |
| 6302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6303 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6304 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6305 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6306 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6307 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6308 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6309 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6310 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6311 | spdy::SpdySerializedFrame body1( |
| 6312 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6313 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6314 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6315 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6316 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6318 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6319 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6320 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6321 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6322 | spdy::SpdySerializedFrame body2( |
| 6323 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6324 | |
| 6325 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6326 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6327 | }; |
| 6328 | |
| 6329 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6330 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6331 | CreateMockRead(body1, 2, ASYNC), |
| 6332 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6333 | CreateMockRead(body2, 5, ASYNC), |
| 6334 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6335 | }; |
| 6336 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6337 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6338 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6339 | |
| 6340 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6341 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6343 | |
| 6344 | TestCompletionCallback callback; |
| 6345 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6346 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6347 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6348 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6349 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6350 | |
| 6351 | LoadTimingInfo load_timing_info; |
| 6352 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6353 | TestLoadTimingNotReused(load_timing_info, |
| 6354 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6355 | |
| 6356 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6357 | ASSERT_TRUE(response); |
| 6358 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6359 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6360 | |
| 6361 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6362 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6363 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6364 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | // Delete the first request, so the second one can reuse the socket. |
| 6366 | trans.reset(); |
| 6367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6368 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6369 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6371 | |
| 6372 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6374 | TestLoadTimingReused(load_timing_info2); |
| 6375 | |
| 6376 | // The requests should have the same ID. |
| 6377 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6378 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6379 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6380 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6381 | } |
| 6382 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6383 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6384 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6385 | // would break socket pool isolation. |
| 6386 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6387 | ProxyConfig proxy_config; |
| 6388 | proxy_config.set_auto_detect(true); |
| 6389 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6390 | |
| 6391 | CapturingProxyResolver capturing_proxy_resolver; |
| 6392 | session_deps_.proxy_resolution_service = |
| 6393 | std::make_unique<ProxyResolutionService>( |
| 6394 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6395 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6396 | std::make_unique<CapturingProxyResolverFactory>( |
| 6397 | &capturing_proxy_resolver), |
| 6398 | nullptr); |
| 6399 | |
| 6400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6401 | |
| 6402 | SpdyTestUtil spdy_util1; |
| 6403 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6404 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6405 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6406 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6407 | // fetch https://www.example.org/ via HTTP/2. |
| 6408 | const char kMyUrl[] = "https://www.example.org/"; |
| 6409 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6410 | spdy::SpdySerializedFrame wrapped_get( |
| 6411 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6412 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6413 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6414 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6415 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6416 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6417 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6418 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6419 | spdy::SpdySerializedFrame wrapped_body( |
| 6420 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6421 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6422 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6423 | spdy::SpdySerializedFrame window_update_body( |
| 6424 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6425 | |
| 6426 | MockWrite spdy_writes1[] = { |
| 6427 | CreateMockWrite(connect, 0), |
| 6428 | CreateMockWrite(wrapped_get, 2), |
| 6429 | CreateMockWrite(window_update_get_resp, 6), |
| 6430 | CreateMockWrite(window_update_body, 7), |
| 6431 | }; |
| 6432 | |
| 6433 | MockRead spdy_reads1[] = { |
| 6434 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6435 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6436 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6437 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6438 | MockRead(ASYNC, 0, 8), |
| 6439 | }; |
| 6440 | |
| 6441 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6442 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6443 | |
| 6444 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6445 | // a new pipe. |
| 6446 | SpdyTestUtil spdy_util2; |
| 6447 | spdy::SpdySerializedFrame req( |
| 6448 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6449 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6450 | |
| 6451 | spdy::SpdySerializedFrame resp( |
| 6452 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6453 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6454 | MockRead spdy_reads2[] = { |
| 6455 | CreateMockRead(resp, 1), |
| 6456 | CreateMockRead(data, 2), |
| 6457 | MockRead(ASYNC, 0, 3), |
| 6458 | }; |
| 6459 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6460 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6461 | |
| 6462 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6463 | ssl.next_proto = kProtoHTTP2; |
| 6464 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6465 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6466 | ssl2.next_proto = kProtoHTTP2; |
| 6467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6468 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6469 | ssl3.next_proto = kProtoHTTP2; |
| 6470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6471 | |
| 6472 | TestCompletionCallback callback; |
| 6473 | std::string response_data; |
| 6474 | |
| 6475 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6476 | capturing_proxy_resolver.set_proxy_server( |
| 6477 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6478 | HttpRequestInfo request1; |
| 6479 | request1.method = "GET"; |
| 6480 | request1.url = GURL("https://www.example.org/"); |
| 6481 | request1.traffic_annotation = |
| 6482 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6483 | |
| 6484 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6485 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6487 | |
| 6488 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6489 | base::RunLoop().RunUntilIdle(); |
| 6490 | // Now allow the read of the response to complete. |
| 6491 | spdy_data1.Resume(); |
| 6492 | rv = callback.WaitForResult(); |
| 6493 | EXPECT_THAT(rv, IsOk()); |
| 6494 | |
| 6495 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6496 | ASSERT_TRUE(response); |
| 6497 | ASSERT_TRUE(response->headers); |
| 6498 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6499 | |
| 6500 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6501 | EXPECT_EQ(kUploadData, response_data); |
| 6502 | RunUntilIdle(); |
| 6503 | |
| 6504 | // Make a direct HTTP/2 request to proxy:70. |
| 6505 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6506 | HttpRequestInfo request2; |
| 6507 | request2.method = "GET"; |
| 6508 | request2.url = GURL("https://proxy:70/"); |
| 6509 | request2.traffic_annotation = |
| 6510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6511 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6512 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6513 | NetLogWithSource())), |
| 6514 | IsOk()); |
| 6515 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6516 | } |
| 6517 | |
| 6518 | // Same as above, but reverse request order, since the code to check for an |
| 6519 | // existing session is different for tunnels and direct connections. |
| 6520 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6521 | // Configure against https proxy server "myproxy:80". |
| 6522 | ProxyConfig proxy_config; |
| 6523 | proxy_config.set_auto_detect(true); |
| 6524 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6525 | |
| 6526 | CapturingProxyResolver capturing_proxy_resolver; |
| 6527 | session_deps_.proxy_resolution_service = |
| 6528 | std::make_unique<ProxyResolutionService>( |
| 6529 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6530 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6531 | std::make_unique<CapturingProxyResolverFactory>( |
| 6532 | &capturing_proxy_resolver), |
| 6533 | nullptr); |
| 6534 | |
| 6535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6536 | // Fetch https://proxy:70/ via HTTP/2. |
| 6537 | SpdyTestUtil spdy_util1; |
| 6538 | spdy::SpdySerializedFrame req( |
| 6539 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6540 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6541 | |
| 6542 | spdy::SpdySerializedFrame resp( |
| 6543 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6544 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6545 | MockRead spdy_reads1[] = { |
| 6546 | CreateMockRead(resp, 1), |
| 6547 | CreateMockRead(data, 2), |
| 6548 | MockRead(ASYNC, 0, 3), |
| 6549 | }; |
| 6550 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6551 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6552 | |
| 6553 | SpdyTestUtil spdy_util2; |
| 6554 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6555 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6556 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6557 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6558 | // fetch https://www.example.org/ via HTTP/2. |
| 6559 | const char kMyUrl[] = "https://www.example.org/"; |
| 6560 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6561 | spdy::SpdySerializedFrame wrapped_get( |
| 6562 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6563 | spdy::SpdySerializedFrame conn_resp( |
| 6564 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6565 | spdy::SpdySerializedFrame get_resp( |
| 6566 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6567 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6568 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6569 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6570 | spdy::SpdySerializedFrame wrapped_body( |
| 6571 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6572 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6573 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6574 | spdy::SpdySerializedFrame window_update_body( |
| 6575 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6576 | |
| 6577 | MockWrite spdy_writes2[] = { |
| 6578 | CreateMockWrite(connect, 0), |
| 6579 | CreateMockWrite(wrapped_get, 2), |
| 6580 | CreateMockWrite(window_update_get_resp, 6), |
| 6581 | CreateMockWrite(window_update_body, 7), |
| 6582 | }; |
| 6583 | |
| 6584 | MockRead spdy_reads2[] = { |
| 6585 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6586 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6587 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6588 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6589 | MockRead(ASYNC, 0, 8), |
| 6590 | }; |
| 6591 | |
| 6592 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6593 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6594 | |
| 6595 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6596 | ssl.next_proto = kProtoHTTP2; |
| 6597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6598 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6599 | ssl2.next_proto = kProtoHTTP2; |
| 6600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6601 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6602 | ssl3.next_proto = kProtoHTTP2; |
| 6603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6604 | |
| 6605 | TestCompletionCallback callback; |
| 6606 | std::string response_data; |
| 6607 | |
| 6608 | // Make a direct HTTP/2 request to proxy:70. |
| 6609 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6610 | HttpRequestInfo request1; |
| 6611 | request1.method = "GET"; |
| 6612 | request1.url = GURL("https://proxy:70/"); |
| 6613 | request1.traffic_annotation = |
| 6614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6615 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6616 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6617 | NetLogWithSource())), |
| 6618 | IsOk()); |
| 6619 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6620 | RunUntilIdle(); |
| 6621 | |
| 6622 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6623 | capturing_proxy_resolver.set_proxy_server( |
| 6624 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6625 | HttpRequestInfo request2; |
| 6626 | request2.method = "GET"; |
| 6627 | request2.url = GURL("https://www.example.org/"); |
| 6628 | request2.traffic_annotation = |
| 6629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6630 | |
| 6631 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6632 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6634 | |
| 6635 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6636 | base::RunLoop().RunUntilIdle(); |
| 6637 | // Now allow the read of the response to complete. |
| 6638 | spdy_data2.Resume(); |
| 6639 | rv = callback.WaitForResult(); |
| 6640 | EXPECT_THAT(rv, IsOk()); |
| 6641 | |
| 6642 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6643 | ASSERT_TRUE(response2); |
| 6644 | ASSERT_TRUE(response2->headers); |
| 6645 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6646 | |
| 6647 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6648 | EXPECT_EQ(kUploadData, response_data); |
| 6649 | } |
| 6650 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6651 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6652 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6653 | HttpRequestInfo request; |
| 6654 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6655 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6656 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6657 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6658 | request.traffic_annotation = |
| 6659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6660 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6661 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6662 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6663 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6664 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6665 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6666 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6667 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6668 | // Since we have proxy, should use full url |
| 6669 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6670 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6671 | "Host: www.example.org\r\n" |
| 6672 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6674 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6675 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6676 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6677 | "Host: www.example.org\r\n" |
| 6678 | "Proxy-Connection: keep-alive\r\n" |
| 6679 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6680 | }; |
| 6681 | |
| 6682 | // The proxy responds to the GET with a 407, using a persistent |
| 6683 | // connection. |
| 6684 | MockRead data_reads1[] = { |
| 6685 | // No credentials. |
| 6686 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6687 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6688 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6689 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6690 | |
| 6691 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6692 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6693 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6695 | }; |
| 6696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6697 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6699 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6700 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6702 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6706 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6708 | |
| 6709 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6712 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6713 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6714 | TestLoadTimingNotReused(load_timing_info, |
| 6715 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6717 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6718 | ASSERT_TRUE(response); |
| 6719 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6720 | EXPECT_EQ(407, response->headers->response_code()); |
| 6721 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6722 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6723 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6725 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6727 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6729 | |
| 6730 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6732 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6733 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6734 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6735 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6736 | TestLoadTimingReused(load_timing_info); |
| 6737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6738 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6739 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6740 | |
| 6741 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6742 | EXPECT_EQ(200, response->headers->response_code()); |
| 6743 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6744 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6745 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6746 | |
| 6747 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6748 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6749 | } |
| 6750 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6751 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6752 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6753 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6754 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6755 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6756 | request.traffic_annotation = |
| 6757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6758 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6759 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6760 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6761 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6763 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6764 | // Since we have proxy, should try to establish tunnel. |
| 6765 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6766 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6767 | "Host: www.example.org:443\r\n" |
| 6768 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6769 | }; |
| 6770 | |
| 6771 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6772 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6773 | // No response body because the test stops reading here. |
| 6774 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6775 | }; |
| 6776 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6777 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6778 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6780 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6783 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6784 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6786 | |
| 6787 | rv = callback.WaitForResult(); |
| 6788 | EXPECT_EQ(expected_status, rv); |
| 6789 | } |
| 6790 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6791 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6792 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6793 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6794 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6795 | } |
| 6796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6797 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6798 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6799 | } |
| 6800 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6801 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6802 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6803 | } |
| 6804 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6805 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6806 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6807 | } |
| 6808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6809 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6810 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6811 | } |
| 6812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6813 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6814 | ConnectStatusHelper( |
| 6815 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6816 | } |
| 6817 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6818 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6819 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6820 | } |
| 6821 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6822 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6823 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6824 | } |
| 6825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6826 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6827 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6828 | } |
| 6829 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6830 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6831 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6832 | } |
| 6833 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6834 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6835 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6836 | } |
| 6837 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6838 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6839 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6840 | } |
| 6841 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6842 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6843 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6844 | } |
| 6845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6846 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6847 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6848 | } |
| 6849 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6850 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6851 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6852 | } |
| 6853 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6854 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6855 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6856 | } |
| 6857 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6858 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6859 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6860 | } |
| 6861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6862 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6863 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6864 | } |
| 6865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6866 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6867 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6868 | } |
| 6869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6870 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6871 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6872 | } |
| 6873 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6874 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6875 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6876 | } |
| 6877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6878 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6879 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6880 | } |
| 6881 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6882 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6883 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6884 | } |
| 6885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6886 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6887 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6888 | } |
| 6889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6890 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6891 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6892 | } |
| 6893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6894 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6895 | ConnectStatusHelperWithExpectedStatus( |
| 6896 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6897 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6910 | } |
| 6911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6913 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6914 | } |
| 6915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6916 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6917 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6918 | } |
| 6919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6920 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6921 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6922 | } |
| 6923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6924 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6925 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6926 | } |
| 6927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6928 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6929 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6930 | } |
| 6931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6932 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6933 | ConnectStatusHelper( |
| 6934 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6935 | } |
| 6936 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6937 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6938 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6939 | } |
| 6940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6941 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6942 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6943 | } |
| 6944 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6945 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6946 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6947 | } |
| 6948 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6949 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6950 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6951 | } |
| 6952 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6953 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6954 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6955 | } |
| 6956 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6957 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6958 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6959 | } |
| 6960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6961 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6962 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6963 | } |
| 6964 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6965 | // Test the flow when both the proxy server AND origin server require |
| 6966 | // authentication. Again, this uses basic auth for both since that is |
| 6967 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6968 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6969 | HttpRequestInfo request; |
| 6970 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6971 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6972 | request.traffic_annotation = |
| 6973 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6974 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6975 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6976 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6977 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6981 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6982 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6983 | MockWrite( |
| 6984 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6985 | "Host: www.example.org\r\n" |
| 6986 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6987 | }; |
| 6988 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6989 | MockRead data_reads1[] = { |
| 6990 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6991 | // Give a couple authenticate options (only the middle one is actually |
| 6992 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6993 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6994 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6995 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6996 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6997 | // Large content-length -- won't matter, as connection will be reset. |
| 6998 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6999 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7000 | }; |
| 7001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7002 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7003 | // request we should be issuing -- the final header line contains the |
| 7004 | // proxy's credentials. |
| 7005 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7006 | MockWrite( |
| 7007 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7008 | "Host: www.example.org\r\n" |
| 7009 | "Proxy-Connection: keep-alive\r\n" |
| 7010 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7011 | }; |
| 7012 | |
| 7013 | // Now the proxy server lets the request pass through to origin server. |
| 7014 | // The origin server responds with a 401. |
| 7015 | MockRead data_reads2[] = { |
| 7016 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7017 | // Note: We are using the same realm-name as the proxy server. This is |
| 7018 | // completely valid, as realms are unique across hosts. |
| 7019 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7020 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7021 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7022 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7023 | }; |
| 7024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7025 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7026 | // the credentials for both the proxy and origin server. |
| 7027 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7028 | MockWrite( |
| 7029 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7030 | "Host: www.example.org\r\n" |
| 7031 | "Proxy-Connection: keep-alive\r\n" |
| 7032 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7033 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7034 | }; |
| 7035 | |
| 7036 | // Lastly we get the desired content. |
| 7037 | MockRead data_reads3[] = { |
| 7038 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7039 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7040 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7041 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7042 | }; |
| 7043 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7044 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7045 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7046 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7047 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7048 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7049 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7051 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7052 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7053 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7055 | |
| 7056 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7059 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7060 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7061 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7063 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7065 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7066 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7067 | |
| 7068 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7069 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7071 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7072 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7073 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7074 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7075 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7077 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7078 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | |
| 7081 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7084 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7085 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7086 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7087 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7088 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7089 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7090 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7091 | // authorization headers. |
| 7092 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7093 | // The NTLM authentication unit tests are based on known test data from the |
| 7094 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7095 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7096 | // for the implementation and testing of the protocol. |
| 7097 | // |
| 7098 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7099 | |
| 7100 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7101 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7102 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7103 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7104 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7105 | request.traffic_annotation = |
| 7106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7107 | |
| 7108 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7109 | // to other auth schemes. |
| 7110 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7111 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7112 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7113 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7114 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7115 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7116 | // Generate the NTLM messages based on known test data. |
| 7117 | std::string negotiate_msg; |
| 7118 | std::string challenge_msg; |
| 7119 | std::string authenticate_msg; |
| 7120 | base::Base64Encode( |
| 7121 | base::StringPiece( |
| 7122 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7123 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7124 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7125 | base::Base64Encode( |
| 7126 | base::StringPiece( |
| 7127 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7128 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7129 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7130 | base::Base64Encode( |
| 7131 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7132 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7133 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7134 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7135 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7136 | &authenticate_msg); |
| 7137 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7138 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7139 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7140 | "Host: server\r\n" |
| 7141 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7142 | }; |
| 7143 | |
| 7144 | MockRead data_reads1[] = { |
| 7145 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7146 | // Negotiate and NTLM are often requested together. However, we only want |
| 7147 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7148 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7149 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7150 | MockRead("Connection: close\r\n"), |
| 7151 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7152 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7153 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7154 | }; |
| 7155 | |
| 7156 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7157 | // After restarting with a null identity, this is the |
| 7158 | // request we should be issuing -- the final header line contains a Type |
| 7159 | // 1 message. |
| 7160 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7161 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7162 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7163 | "Authorization: NTLM "), |
| 7164 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7166 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7167 | // (using correct credentials). The second request continues on the |
| 7168 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7169 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7170 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7171 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7172 | "Authorization: NTLM "), |
| 7173 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7174 | }; |
| 7175 | |
| 7176 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7177 | // The origin server responds with a Type 2 message. |
| 7178 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7179 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7180 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7181 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7182 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7183 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7184 | // Lastly we get the desired content. |
| 7185 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7186 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7187 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7188 | }; |
| 7189 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7190 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7191 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7192 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7193 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7194 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7195 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7197 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7200 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7203 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7204 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7206 | |
| 7207 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7210 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7212 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7213 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7214 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7216 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7217 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7218 | rv = trans.RestartWithAuth( |
| 7219 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7220 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7222 | |
| 7223 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7224 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7226 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7228 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7229 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7230 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7231 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7232 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7235 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7236 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7237 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7238 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7241 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7242 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7243 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7244 | |
| 7245 | std::string response_data; |
| 7246 | rv = ReadTransaction(&trans, &response_data); |
| 7247 | EXPECT_THAT(rv, IsOk()); |
| 7248 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7249 | |
| 7250 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7251 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7252 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7253 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7254 | } |
| 7255 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7256 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7257 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7258 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7259 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7260 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7261 | request.traffic_annotation = |
| 7262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7263 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7264 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7265 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7266 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7267 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7268 | // Generate the NTLM messages based on known test data. |
| 7269 | std::string negotiate_msg; |
| 7270 | std::string challenge_msg; |
| 7271 | std::string authenticate_msg; |
| 7272 | base::Base64Encode( |
| 7273 | base::StringPiece( |
| 7274 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7275 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7276 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7277 | base::Base64Encode( |
| 7278 | base::StringPiece( |
| 7279 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7280 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7281 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7282 | base::Base64Encode( |
| 7283 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7284 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7285 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7286 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7287 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7288 | &authenticate_msg); |
| 7289 | |
| 7290 | // The authenticate message when |kWrongPassword| is sent. |
| 7291 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7292 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7293 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7294 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7295 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7296 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7297 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7298 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7299 | // Sanity check that it's the same length as the correct authenticate message |
| 7300 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7301 | ASSERT_EQ(authenticate_msg.length(), |
| 7302 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7303 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7304 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7305 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7306 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7307 | "Host: server\r\n" |
| 7308 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7309 | }; |
| 7310 | |
| 7311 | MockRead data_reads1[] = { |
| 7312 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7313 | // Negotiate and NTLM are often requested together. However, we only want |
| 7314 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7315 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7316 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7317 | MockRead("Connection: close\r\n"), |
| 7318 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7319 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7320 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7321 | }; |
| 7322 | |
| 7323 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7324 | // After restarting with a null identity, this is the |
| 7325 | // request we should be issuing -- the final header line contains a Type |
| 7326 | // 1 message. |
| 7327 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7328 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7329 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7330 | "Authorization: NTLM "), |
| 7331 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7333 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7334 | // (using incorrect credentials). The second request continues on the |
| 7335 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7336 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7337 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7338 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7339 | "Authorization: NTLM "), |
| 7340 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7341 | }; |
| 7342 | |
| 7343 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7344 | // The origin server responds with a Type 2 message. |
| 7345 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7346 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7347 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7348 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7349 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7350 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7351 | // Wrong password. |
| 7352 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7353 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7354 | MockRead("Content-Length: 42\r\n"), |
| 7355 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7356 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7357 | }; |
| 7358 | |
| 7359 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7360 | // After restarting with a null identity, this is the |
| 7361 | // request we should be issuing -- the final header line contains a Type |
| 7362 | // 1 message. |
| 7363 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7364 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7365 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7366 | "Authorization: NTLM "), |
| 7367 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7369 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7370 | // (the credentials for the origin server). The second request continues |
| 7371 | // on the same connection. |
| 7372 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7373 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7374 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7375 | "Authorization: NTLM "), |
| 7376 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7377 | }; |
| 7378 | |
| 7379 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7380 | // The origin server responds with a Type 2 message. |
| 7381 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7382 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7383 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7384 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7385 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7386 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7387 | // Lastly we get the desired content. |
| 7388 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7389 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7390 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7391 | }; |
| 7392 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7393 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7394 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7395 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7396 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7397 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7398 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7399 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7400 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7402 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7404 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7407 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7409 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7410 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7411 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7413 | |
| 7414 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7417 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7419 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7420 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7421 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7422 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7423 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7424 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7425 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7426 | rv = trans.RestartWithAuth( |
| 7427 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7428 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7430 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7431 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7434 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7435 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7436 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7438 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7439 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7440 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7442 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7443 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7444 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7446 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7447 | |
| 7448 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7449 | rv = trans.RestartWithAuth( |
| 7450 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7451 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7453 | |
| 7454 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7455 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7457 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7459 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7460 | |
| 7461 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7462 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7464 | |
| 7465 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7468 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7469 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7470 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7471 | |
| 7472 | std::string response_data; |
| 7473 | rv = ReadTransaction(&trans, &response_data); |
| 7474 | EXPECT_THAT(rv, IsOk()); |
| 7475 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7476 | |
| 7477 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7478 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7479 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7480 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7481 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7482 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7483 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7484 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7485 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7486 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7487 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7488 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7489 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7490 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7491 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7492 | |
| 7493 | HttpRequestInfo request; |
| 7494 | request.method = "GET"; |
| 7495 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7496 | request.traffic_annotation = |
| 7497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7498 | |
| 7499 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7500 | spdy::SpdyHeaderBlock request_headers0( |
| 7501 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7502 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7503 | 1, std::move(request_headers0), LOWEST, true)); |
| 7504 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7505 | spdy::SpdyHeaderBlock response_headers0; |
| 7506 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7507 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7508 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7509 | 1, std::move(response_headers0), true)); |
| 7510 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7511 | // Stream 1 is closed. |
| 7512 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7513 | |
| 7514 | // Generate the NTLM messages based on known test data. |
| 7515 | std::string negotiate_msg; |
| 7516 | std::string challenge_msg; |
| 7517 | std::string authenticate_msg; |
| 7518 | base::Base64Encode( |
| 7519 | base::StringPiece( |
| 7520 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7521 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7522 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7523 | base::Base64Encode( |
| 7524 | base::StringPiece( |
| 7525 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7526 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7527 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7528 | base::Base64Encode( |
| 7529 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7530 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7531 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7532 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7533 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7534 | &authenticate_msg); |
| 7535 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7536 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7537 | MockRead reads0[] = {CreateMockRead(resp, 1), |
| 7538 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7539 | |
| 7540 | // Retry yet again using HTTP/1.1. |
| 7541 | MockWrite writes1[] = { |
| 7542 | // After restarting with a null identity, this is the |
| 7543 | // request we should be issuing -- the final header line contains a Type |
| 7544 | // 1 message. |
| 7545 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7546 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7547 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7548 | "Authorization: NTLM "), |
| 7549 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7550 | |
| 7551 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7552 | // (the credentials for the origin server). The second request continues |
| 7553 | // on the same connection. |
| 7554 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7555 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7556 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7557 | "Authorization: NTLM "), |
| 7558 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7559 | }; |
| 7560 | |
| 7561 | MockRead reads1[] = { |
| 7562 | // The origin server responds with a Type 2 message. |
| 7563 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7564 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7565 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7566 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7567 | MockRead("You are not authorized to view this page\r\n"), |
| 7568 | |
| 7569 | // Lastly we get the desired content. |
| 7570 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7571 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7572 | 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] | 7573 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7574 | SequencedSocketData data0(reads0, writes0); |
| 7575 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7576 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7577 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7578 | |
| 7579 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7580 | ssl0.next_proto = kProtoHTTP2; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7581 | ssl0.next_protos_expected_in_ssl_config = |
| 7582 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7583 | SSLSocketDataProvider ssl1(ASYNC, OK); |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7584 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 7585 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7588 | |
| 7589 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7591 | |
| 7592 | TestCompletionCallback callback1; |
| 7593 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7595 | |
| 7596 | rv = callback1.WaitForResult(); |
| 7597 | EXPECT_THAT(rv, IsOk()); |
| 7598 | |
| 7599 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7600 | |
| 7601 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7602 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7603 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7604 | |
| 7605 | TestCompletionCallback callback2; |
| 7606 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7607 | rv = trans.RestartWithAuth( |
| 7608 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7609 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7611 | |
| 7612 | rv = callback2.WaitForResult(); |
| 7613 | EXPECT_THAT(rv, IsOk()); |
| 7614 | |
| 7615 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7616 | |
| 7617 | response = trans.GetResponseInfo(); |
| 7618 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7619 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7620 | |
| 7621 | TestCompletionCallback callback3; |
| 7622 | |
| 7623 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7625 | |
| 7626 | rv = callback3.WaitForResult(); |
| 7627 | EXPECT_THAT(rv, IsOk()); |
| 7628 | |
| 7629 | response = trans.GetResponseInfo(); |
| 7630 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7631 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7632 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7633 | |
| 7634 | std::string response_data; |
| 7635 | rv = ReadTransaction(&trans, &response_data); |
| 7636 | EXPECT_THAT(rv, IsOk()); |
| 7637 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7638 | |
| 7639 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7640 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7641 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7642 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7643 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7644 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 7645 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 7646 | |
| 7647 | // Variant of above test using WebSockets. |
| 7648 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2WithWebsockets) { |
| 7649 | const GURL kInitialUrl("https://server/"); |
| 7650 | const GURL kWebSocketUrl("wss://server/"); |
| 7651 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7652 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7653 | |
| 7654 | // Initial request establishes an H2 connection, which will then be reused for |
| 7655 | // WebSockets. This is needed since WebSockets will reuse H2 connections, but |
| 7656 | // it won't create a new one. |
| 7657 | spdy::SpdyHeaderBlock initial_request_headers( |
| 7658 | spdy_util_.ConstructGetHeaderBlock(kInitialUrl.spec())); |
| 7659 | spdy::SpdySerializedFrame initial_request(spdy_util_.ConstructSpdyHeaders( |
| 7660 | 1, std::move(initial_request_headers), DEFAULT_PRIORITY, true)); |
| 7661 | spdy::SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 7662 | |
| 7663 | // Settings frame, indicating WebSockets is supported. |
| 7664 | spdy::SettingsMap settings; |
| 7665 | settings[spdy::SETTINGS_ENABLE_CONNECT_PROTOCOL] = 1; |
| 7666 | spdy::SpdySerializedFrame settings_frame( |
| 7667 | spdy_util_.ConstructSpdySettings(settings)); |
| 7668 | |
| 7669 | // Response headers for first request. Body is never received, but that |
| 7670 | // shouldn't matter for the purposes of this test. |
| 7671 | spdy::SpdySerializedFrame initial_response( |
| 7672 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7673 | |
| 7674 | // First WebSocket request, which has no credentials. |
| 7675 | spdy::SpdyHeaderBlock websocket_request_headers; |
| 7676 | websocket_request_headers[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 7677 | websocket_request_headers[spdy::kHttp2AuthorityHeader] = "server"; |
| 7678 | websocket_request_headers[spdy::kHttp2SchemeHeader] = "https"; |
| 7679 | websocket_request_headers[spdy::kHttp2PathHeader] = "/"; |
| 7680 | websocket_request_headers[spdy::kHttp2ProtocolHeader] = "websocket"; |
| 7681 | websocket_request_headers["origin"] = "http://server"; |
| 7682 | websocket_request_headers["sec-websocket-version"] = "13"; |
| 7683 | websocket_request_headers["sec-websocket-extensions"] = |
| 7684 | "permessage-deflate; client_max_window_bits"; |
| 7685 | spdy::SpdySerializedFrame websocket_request(spdy_util_.ConstructSpdyHeaders( |
| 7686 | 3, std::move(websocket_request_headers), MEDIUM, false)); |
| 7687 | |
| 7688 | // Auth challenge to WebSocket request. |
| 7689 | spdy::SpdyHeaderBlock auth_challenge_headers; |
| 7690 | auth_challenge_headers[spdy::kHttp2StatusHeader] = "401"; |
| 7691 | auth_challenge_headers["www-authenticate"] = "NTLM"; |
| 7692 | spdy::SpdySerializedFrame websocket_auth_challenge( |
| 7693 | spdy_util_.ConstructSpdyResponseHeaders( |
| 7694 | 3, std::move(auth_challenge_headers), true)); |
| 7695 | |
| 7696 | MockWrite writes0[] = {CreateMockWrite(initial_request, 0), |
| 7697 | CreateMockWrite(settings_ack, 2), |
| 7698 | CreateMockWrite(websocket_request, 4), |
| 7699 | MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 7)}; |
| 7700 | MockRead reads0[] = {CreateMockRead(settings_frame, 1), |
| 7701 | CreateMockRead(initial_response, 3), |
| 7702 | CreateMockRead(websocket_auth_challenge, 5), |
| 7703 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6)}; |
| 7704 | |
| 7705 | // Generate the NTLM messages based on known test data. |
| 7706 | std::string negotiate_msg; |
| 7707 | std::string challenge_msg; |
| 7708 | std::string authenticate_msg; |
| 7709 | base::Base64Encode( |
| 7710 | base::StringPiece( |
| 7711 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 7712 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
| 7713 | &negotiate_msg); |
| 7714 | base::Base64Encode( |
| 7715 | base::StringPiece( |
| 7716 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 7717 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
| 7718 | &challenge_msg); |
| 7719 | base::Base64Encode( |
| 7720 | base::StringPiece( |
| 7721 | reinterpret_cast<const char*>( |
| 7722 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 7723 | base::size( |
| 7724 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7725 | &authenticate_msg); |
| 7726 | |
| 7727 | // Retry yet again using HTTP/1.1. |
| 7728 | MockWrite writes1[] = { |
| 7729 | // After restarting with a null identity, this is the |
| 7730 | // request we should be issuing -- the final header line contains a Type |
| 7731 | // 1 message. |
| 7732 | MockWrite("GET / HTTP/1.1\r\n" |
| 7733 | "Host: server\r\n" |
| 7734 | "Connection: Upgrade\r\n" |
| 7735 | "Authorization: NTLM "), |
| 7736 | MockWrite(negotiate_msg.c_str()), |
| 7737 | MockWrite("\r\n"), |
| 7738 | MockWrite("Origin: http://server\r\n" |
| 7739 | "Sec-WebSocket-Version: 13\r\n" |
| 7740 | "Upgrade: websocket\r\n" |
| 7741 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 7742 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 7743 | "client_max_window_bits\r\n\r\n"), |
| 7744 | |
| 7745 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7746 | // (the credentials for the origin server). The second request continues |
| 7747 | // on the same connection. |
| 7748 | MockWrite("GET / HTTP/1.1\r\n" |
| 7749 | "Host: server\r\n" |
| 7750 | "Connection: Upgrade\r\n" |
| 7751 | "Authorization: NTLM "), |
| 7752 | MockWrite(authenticate_msg.c_str()), |
| 7753 | MockWrite("\r\n"), |
| 7754 | MockWrite("Origin: http://server\r\n" |
| 7755 | "Sec-WebSocket-Version: 13\r\n" |
| 7756 | "Upgrade: websocket\r\n" |
| 7757 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 7758 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 7759 | "client_max_window_bits\r\n\r\n"), |
| 7760 | }; |
| 7761 | |
| 7762 | MockRead reads1[] = { |
| 7763 | // The origin server responds with a Type 2 message. |
| 7764 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7765 | MockRead("WWW-Authenticate: NTLM "), |
| 7766 | MockRead(challenge_msg.c_str()), |
| 7767 | MockRead("\r\n"), |
| 7768 | MockRead("Content-Length: 42\r\n"), |
| 7769 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7770 | MockRead("You are not authorized to view this page\r\n"), |
| 7771 | |
| 7772 | // Lastly we get the desired content. |
| 7773 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 7774 | "Upgrade: websocket\r\n" |
| 7775 | "Connection: Upgrade\r\n" |
| 7776 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 7777 | }; |
| 7778 | SequencedSocketData data0(reads0, writes0); |
| 7779 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7780 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7781 | ssl0.next_proto = kProtoHTTP2; |
| 7782 | ssl0.next_protos_expected_in_ssl_config = |
| 7783 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
| 7784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7785 | |
| 7786 | StaticSocketDataProvider data1(reads1, writes1); |
| 7787 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7788 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7789 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 7790 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{}; |
| 7791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7792 | |
| 7793 | session_deps_.enable_websocket_over_http2 = true; |
| 7794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7795 | |
| 7796 | HttpRequestInfo initial_request_info; |
| 7797 | initial_request_info.method = "GET"; |
| 7798 | initial_request_info.url = kInitialUrl; |
| 7799 | initial_request_info.traffic_annotation = |
| 7800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7801 | HttpNetworkTransaction initial_trans(DEFAULT_PRIORITY, session.get()); |
| 7802 | TestCompletionCallback initial_callback; |
| 7803 | int rv = initial_trans.Start(&initial_request_info, |
| 7804 | initial_callback.callback(), NetLogWithSource()); |
| 7805 | EXPECT_THAT(initial_callback.GetResult(rv), IsOk()); |
| 7806 | |
| 7807 | EXPECT_FALSE(session->http_server_properties()->RequiresHTTP11( |
| 7808 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 7809 | |
| 7810 | HttpRequestInfo websocket_request_info; |
| 7811 | websocket_request_info.method = "GET"; |
| 7812 | websocket_request_info.url = kWebSocketUrl; |
| 7813 | websocket_request_info.traffic_annotation = |
| 7814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7815 | EXPECT_TRUE(HostPortPair::FromURL(initial_request_info.url) |
| 7816 | .Equals(HostPortPair::FromURL(websocket_request_info.url))); |
| 7817 | websocket_request_info.extra_headers.SetHeader("Origin", "http://server"); |
| 7818 | websocket_request_info.extra_headers.SetHeader("Sec-WebSocket-Version", "13"); |
| 7819 | // The following two headers must be removed by WebSocketHttp2HandshakeStream. |
| 7820 | websocket_request_info.extra_headers.SetHeader("Connection", "Upgrade"); |
| 7821 | websocket_request_info.extra_headers.SetHeader("Upgrade", "websocket"); |
| 7822 | |
| 7823 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 7824 | |
| 7825 | HttpNetworkTransaction websocket_trans(MEDIUM, session.get()); |
| 7826 | websocket_trans.SetWebSocketHandshakeStreamCreateHelper( |
| 7827 | &websocket_stream_create_helper); |
| 7828 | |
| 7829 | TestCompletionCallback websocket_callback; |
| 7830 | rv = websocket_trans.Start(&websocket_request_info, |
| 7831 | websocket_callback.callback(), NetLogWithSource()); |
| 7832 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 7833 | |
| 7834 | EXPECT_FALSE(websocket_trans.IsReadyToRestartForAuth()); |
| 7835 | |
| 7836 | const HttpResponseInfo* response = websocket_trans.GetResponseInfo(); |
| 7837 | ASSERT_TRUE(response); |
| 7838 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
| 7839 | |
| 7840 | rv = websocket_trans.RestartWithAuth( |
| 7841 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7842 | websocket_callback.callback()); |
| 7843 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 7844 | |
| 7845 | EXPECT_TRUE(websocket_trans.IsReadyToRestartForAuth()); |
| 7846 | |
| 7847 | response = websocket_trans.GetResponseInfo(); |
| 7848 | ASSERT_TRUE(response); |
| 7849 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 7850 | |
| 7851 | rv = websocket_trans.RestartWithAuth(AuthCredentials(), |
| 7852 | websocket_callback.callback()); |
| 7853 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 7854 | |
| 7855 | // The server should have been marked as requiring HTTP/1.1. The important |
| 7856 | // part here is that the scheme that requires HTTP/1.1 should be HTTPS, not |
| 7857 | // WSS. |
| 7858 | EXPECT_TRUE(session->http_server_properties()->RequiresHTTP11( |
| 7859 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 7860 | } |
| 7861 | |
| 7862 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 7863 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7864 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7865 | // do no retry forever checking for TLS version interference. This is a |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7866 | // regression test for https://crbug.com/823387. The version interference probe |
| 7867 | // has since been removed, but retain the regression test so we can update it if |
| 7868 | // we add future TLS retries. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7869 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7870 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7871 | // https://origin/. |
| 7872 | session_deps_.proxy_resolution_service = |
| 7873 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7874 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7875 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 7876 | SSLContextConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7877 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7878 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7879 | |
| 7880 | HttpRequestInfo request; |
| 7881 | request.method = "GET"; |
| 7882 | request.url = GURL("https://origin/"); |
| 7883 | request.traffic_annotation = |
| 7884 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7885 | |
| 7886 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7887 | // to other auth schemes. |
| 7888 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7889 | |
| 7890 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7891 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7893 | |
| 7894 | // Generate the NTLM messages based on known test data. |
| 7895 | std::string negotiate_msg; |
| 7896 | std::string challenge_msg; |
| 7897 | std::string authenticate_msg; |
| 7898 | base::Base64Encode( |
| 7899 | base::StringPiece( |
| 7900 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7901 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7902 | &negotiate_msg); |
| 7903 | base::Base64Encode( |
| 7904 | base::StringPiece( |
| 7905 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7906 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7907 | &challenge_msg); |
| 7908 | base::Base64Encode( |
| 7909 | base::StringPiece( |
| 7910 | reinterpret_cast<const char*>( |
| 7911 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7912 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7913 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7914 | &authenticate_msg); |
| 7915 | |
| 7916 | MockWrite data_writes[] = { |
| 7917 | // The initial CONNECT request. |
| 7918 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7919 | "Host: origin:443\r\n" |
| 7920 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7921 | |
| 7922 | // After restarting with an identity. |
| 7923 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7924 | "Host: origin:443\r\n" |
| 7925 | "Proxy-Connection: keep-alive\r\n" |
| 7926 | "Proxy-Authorization: NTLM "), |
| 7927 | MockWrite(negotiate_msg.c_str()), |
| 7928 | // End headers. |
| 7929 | MockWrite("\r\n\r\n"), |
| 7930 | |
| 7931 | // The second restart. |
| 7932 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7933 | "Host: origin:443\r\n" |
| 7934 | "Proxy-Connection: keep-alive\r\n" |
| 7935 | "Proxy-Authorization: NTLM "), |
| 7936 | MockWrite(authenticate_msg.c_str()), |
| 7937 | // End headers. |
| 7938 | MockWrite("\r\n\r\n"), |
| 7939 | }; |
| 7940 | |
| 7941 | MockRead data_reads[] = { |
| 7942 | // The initial NTLM response. |
| 7943 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7944 | "Content-Length: 0\r\n" |
| 7945 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7946 | |
| 7947 | // The NTLM challenge message. |
| 7948 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7949 | "Content-Length: 0\r\n" |
| 7950 | "Proxy-Authenticate: NTLM "), |
| 7951 | MockRead(challenge_msg.c_str()), |
| 7952 | // End headers. |
| 7953 | MockRead("\r\n\r\n"), |
| 7954 | |
| 7955 | // Finally the tunnel is established. |
| 7956 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7957 | }; |
| 7958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7959 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7960 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7963 | |
| 7964 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7965 | // request. |
| 7966 | TestCompletionCallback callback; |
| 7967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7968 | int rv = callback.GetResult( |
| 7969 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7970 | |
| 7971 | EXPECT_THAT(rv, IsOk()); |
| 7972 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7973 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7974 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7975 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7976 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7977 | // Configure credentials and restart. The proxy responds with the challenge |
| 7978 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7979 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7980 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7981 | callback.callback())); |
| 7982 | EXPECT_THAT(rv, IsOk()); |
| 7983 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7984 | response = trans.GetResponseInfo(); |
| 7985 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7986 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7987 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7988 | // Restart once more. The tunnel will be established and then the SSL |
| 7989 | // handshake will reset. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7990 | rv = callback.GetResult( |
| 7991 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7992 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7993 | } |
| 7994 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7995 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7996 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7997 | // Test reading a server response which has only headers, and no body. |
| 7998 | // After some maximum number of bytes is consumed, the transaction should |
| 7999 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8000 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8001 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8002 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8003 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8004 | request.traffic_annotation = |
| 8005 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8006 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8008 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8009 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8010 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 8011 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8012 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8013 | |
| 8014 | MockRead data_reads[] = { |
| 8015 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8016 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8017 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8018 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8019 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8020 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8021 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8023 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8024 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8025 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8027 | |
| 8028 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8029 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8030 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8031 | |
| 8032 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 8033 | // establish tunnel. |
| 8034 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8035 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8036 | HttpRequestInfo request; |
| 8037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8038 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8039 | request.traffic_annotation = |
| 8040 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8041 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8042 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8043 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8044 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 8045 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8047 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8048 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8049 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8050 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8051 | // Since we have proxy, should try to establish tunnel. |
| 8052 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8053 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8054 | "Host: www.example.org:443\r\n" |
| 8055 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8056 | }; |
| 8057 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 8058 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8059 | // connection. Usually a proxy would return 501 (not implemented), |
| 8060 | // or 200 (tunnel established). |
| 8061 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 8062 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8063 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8064 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8065 | }; |
| 8066 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8067 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8068 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8070 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8072 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8074 | |
| 8075 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8076 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8077 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8078 | // Empty the current queue. This is necessary because idle sockets are |
| 8079 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8080 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8081 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8082 | // We now check to make sure the TCPClientSocket was not added back to |
| 8083 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8084 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8085 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8086 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8087 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8088 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8089 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8090 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8091 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8092 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8093 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8095 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8096 | request.traffic_annotation = |
| 8097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8101 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8102 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8103 | MockRead data_reads[] = { |
| 8104 | // A part of the response body is received with the response headers. |
| 8105 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8106 | // The rest of the response body is received in two parts. |
| 8107 | MockRead("lo"), |
| 8108 | MockRead(" world"), |
| 8109 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8111 | }; |
| 8112 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8113 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8114 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8116 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8118 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8120 | |
| 8121 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8122 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8124 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8125 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8126 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8127 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8128 | std::string status_line = response->headers->GetStatusLine(); |
| 8129 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8130 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8131 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8132 | |
| 8133 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8134 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8136 | EXPECT_EQ("hello world", response_data); |
| 8137 | |
| 8138 | // Empty the current queue. This is necessary because idle sockets are |
| 8139 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8140 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8141 | |
| 8142 | // 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] | 8143 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8144 | } |
| 8145 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8146 | // Make sure that we recycle a SSL socket after reading all of the response |
| 8147 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8148 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8149 | HttpRequestInfo request; |
| 8150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8151 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8152 | request.traffic_annotation = |
| 8153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8154 | |
| 8155 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8156 | MockWrite( |
| 8157 | "GET / HTTP/1.1\r\n" |
| 8158 | "Host: www.example.org\r\n" |
| 8159 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8160 | }; |
| 8161 | |
| 8162 | MockRead data_reads[] = { |
| 8163 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8164 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8165 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8166 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8167 | }; |
| 8168 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8169 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8171 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8172 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8175 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8176 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8177 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8178 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8179 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8180 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8181 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8183 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8185 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8186 | ASSERT_TRUE(response); |
| 8187 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8188 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8189 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8190 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8191 | |
| 8192 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8193 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8194 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8195 | EXPECT_EQ("hello world", response_data); |
| 8196 | |
| 8197 | // Empty the current queue. This is necessary because idle sockets are |
| 8198 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8199 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8200 | |
| 8201 | // 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] | 8202 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8203 | } |
| 8204 | |
| 8205 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8206 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8207 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8208 | HttpRequestInfo request; |
| 8209 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8210 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8211 | request.traffic_annotation = |
| 8212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8213 | |
| 8214 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8215 | MockWrite( |
| 8216 | "GET / HTTP/1.1\r\n" |
| 8217 | "Host: www.example.org\r\n" |
| 8218 | "Connection: keep-alive\r\n\r\n"), |
| 8219 | MockWrite( |
| 8220 | "GET / HTTP/1.1\r\n" |
| 8221 | "Host: www.example.org\r\n" |
| 8222 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8223 | }; |
| 8224 | |
| 8225 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8226 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8227 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8228 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8229 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8230 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8233 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8234 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8235 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8236 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8237 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8239 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8240 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8242 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8243 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8244 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8245 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8246 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8248 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8249 | |
| 8250 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8251 | ASSERT_TRUE(response); |
| 8252 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8253 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8254 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8255 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8256 | |
| 8257 | std::string response_data; |
| 8258 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8260 | EXPECT_EQ("hello world", response_data); |
| 8261 | |
| 8262 | // Empty the current queue. This is necessary because idle sockets are |
| 8263 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8264 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8265 | |
| 8266 | // 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] | 8267 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8268 | |
| 8269 | // Now start the second transaction, which should reuse the previous socket. |
| 8270 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8271 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8272 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8273 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8274 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8275 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8277 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8278 | |
| 8279 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8280 | ASSERT_TRUE(response); |
| 8281 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8282 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8283 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8284 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8285 | |
| 8286 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8288 | EXPECT_EQ("hello world", response_data); |
| 8289 | |
| 8290 | // Empty the current queue. This is necessary because idle sockets are |
| 8291 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8292 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8293 | |
| 8294 | // 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] | 8295 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8296 | } |
| 8297 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8298 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8299 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8300 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8301 | HttpRequestInfo request; |
| 8302 | request.method = "GET"; |
| 8303 | request.url = GURL("http://www.example.org/"); |
| 8304 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8305 | request.traffic_annotation = |
| 8306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8307 | |
| 8308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8311 | |
| 8312 | MockRead data_reads[] = { |
| 8313 | // A part of the response body is received with the response headers. |
| 8314 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8315 | // The rest of the response body is received in two parts. |
| 8316 | MockRead("lo"), MockRead(" world"), |
| 8317 | MockRead("junk"), // Should not be read!! |
| 8318 | MockRead(SYNCHRONOUS, OK), |
| 8319 | }; |
| 8320 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8321 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8322 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8323 | |
| 8324 | TestCompletionCallback callback; |
| 8325 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8326 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8327 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8328 | |
| 8329 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8332 | ASSERT_TRUE(response); |
| 8333 | EXPECT_TRUE(response->headers); |
| 8334 | std::string status_line = response->headers->GetStatusLine(); |
| 8335 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8336 | |
| 8337 | // Make memory critical notification and ensure the transaction still has been |
| 8338 | // operating right. |
| 8339 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8340 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8341 | base::RunLoop().RunUntilIdle(); |
| 8342 | |
| 8343 | // Socket should not be flushed as long as it is not idle. |
| 8344 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8345 | |
| 8346 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8347 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8348 | EXPECT_THAT(rv, IsOk()); |
| 8349 | EXPECT_EQ("hello world", response_data); |
| 8350 | |
| 8351 | // Empty the current queue. This is necessary because idle sockets are |
| 8352 | // added to the connection pool asynchronously with a PostTask. |
| 8353 | base::RunLoop().RunUntilIdle(); |
| 8354 | |
| 8355 | // We now check to make sure the socket was added back to the pool. |
| 8356 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8357 | |
| 8358 | // Idle sockets should be flushed now. |
| 8359 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8360 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8361 | base::RunLoop().RunUntilIdle(); |
| 8362 | |
| 8363 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8364 | } |
| 8365 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8366 | // Disable idle socket closing on memory pressure. |
| 8367 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8368 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8369 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8370 | HttpRequestInfo request; |
| 8371 | request.method = "GET"; |
| 8372 | request.url = GURL("http://www.example.org/"); |
| 8373 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8374 | request.traffic_annotation = |
| 8375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8376 | |
| 8377 | // Disable idle socket closing on memory pressure. |
| 8378 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8380 | |
| 8381 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8382 | |
| 8383 | MockRead data_reads[] = { |
| 8384 | // A part of the response body is received with the response headers. |
| 8385 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8386 | // The rest of the response body is received in two parts. |
| 8387 | MockRead("lo"), MockRead(" world"), |
| 8388 | MockRead("junk"), // Should not be read!! |
| 8389 | MockRead(SYNCHRONOUS, OK), |
| 8390 | }; |
| 8391 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8392 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8393 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8394 | |
| 8395 | TestCompletionCallback callback; |
| 8396 | |
| 8397 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8398 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8399 | |
| 8400 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8401 | |
| 8402 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8403 | ASSERT_TRUE(response); |
| 8404 | EXPECT_TRUE(response->headers); |
| 8405 | std::string status_line = response->headers->GetStatusLine(); |
| 8406 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8407 | |
| 8408 | // Make memory critical notification and ensure the transaction still has been |
| 8409 | // operating right. |
| 8410 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8411 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8412 | base::RunLoop().RunUntilIdle(); |
| 8413 | |
| 8414 | // Socket should not be flushed as long as it is not idle. |
| 8415 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8416 | |
| 8417 | std::string response_data; |
| 8418 | rv = ReadTransaction(&trans, &response_data); |
| 8419 | EXPECT_THAT(rv, IsOk()); |
| 8420 | EXPECT_EQ("hello world", response_data); |
| 8421 | |
| 8422 | // Empty the current queue. This is necessary because idle sockets are |
| 8423 | // added to the connection pool asynchronously with a PostTask. |
| 8424 | base::RunLoop().RunUntilIdle(); |
| 8425 | |
| 8426 | // We now check to make sure the socket was added back to the pool. |
| 8427 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8428 | |
| 8429 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8430 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8431 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8432 | base::RunLoop().RunUntilIdle(); |
| 8433 | |
| 8434 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8435 | |
| 8436 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8437 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8438 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8439 | base::RunLoop().RunUntilIdle(); |
| 8440 | |
| 8441 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8442 | } |
| 8443 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8444 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8445 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8446 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8447 | HttpRequestInfo request; |
| 8448 | request.method = "GET"; |
| 8449 | request.url = GURL("https://www.example.org/"); |
| 8450 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8451 | request.traffic_annotation = |
| 8452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8453 | |
| 8454 | MockWrite data_writes[] = { |
| 8455 | MockWrite("GET / HTTP/1.1\r\n" |
| 8456 | "Host: www.example.org\r\n" |
| 8457 | "Connection: keep-alive\r\n\r\n"), |
| 8458 | }; |
| 8459 | |
| 8460 | MockRead data_reads[] = { |
| 8461 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8462 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8463 | |
| 8464 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8466 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8467 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8468 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8469 | |
| 8470 | TestCompletionCallback callback; |
| 8471 | |
| 8472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8474 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8475 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8476 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8477 | |
| 8478 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8480 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8481 | ASSERT_TRUE(response); |
| 8482 | ASSERT_TRUE(response->headers); |
| 8483 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8484 | |
| 8485 | // Make memory critical notification and ensure the transaction still has been |
| 8486 | // operating right. |
| 8487 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8488 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8489 | base::RunLoop().RunUntilIdle(); |
| 8490 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8491 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8492 | |
| 8493 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8494 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8495 | EXPECT_THAT(rv, IsOk()); |
| 8496 | EXPECT_EQ("hello world", response_data); |
| 8497 | |
| 8498 | // Empty the current queue. This is necessary because idle sockets are |
| 8499 | // added to the connection pool asynchronously with a PostTask. |
| 8500 | base::RunLoop().RunUntilIdle(); |
| 8501 | |
| 8502 | // 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] | 8503 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8504 | |
| 8505 | // Make memory notification once again and ensure idle socket is closed. |
| 8506 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8507 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8508 | base::RunLoop().RunUntilIdle(); |
| 8509 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8510 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8511 | } |
| 8512 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8513 | // Make sure that we recycle a socket after a zero-length response. |
| 8514 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8515 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8516 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8518 | request.url = GURL( |
| 8519 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8520 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8521 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8522 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8523 | request.traffic_annotation = |
| 8524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8527 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8528 | MockRead data_reads[] = { |
| 8529 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8530 | "Content-Length: 0\r\n" |
| 8531 | "Content-Type: text/html\r\n\r\n"), |
| 8532 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8533 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8534 | }; |
| 8535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8536 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8538 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8539 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8540 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8543 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8545 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8547 | |
| 8548 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8549 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8552 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8553 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8554 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8555 | std::string status_line = response->headers->GetStatusLine(); |
| 8556 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8557 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8558 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8559 | |
| 8560 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8561 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8562 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8563 | EXPECT_EQ("", response_data); |
| 8564 | |
| 8565 | // Empty the current queue. This is necessary because idle sockets are |
| 8566 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8567 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8568 | |
| 8569 | // 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] | 8570 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8571 | } |
| 8572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8573 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8574 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8575 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8576 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8577 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8578 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8579 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8580 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8581 | // after use. |
| 8582 | request[0].method = "GET"; |
| 8583 | request[0].url = GURL("http://www.google.com/"); |
| 8584 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8585 | request[0].traffic_annotation = |
| 8586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8587 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8588 | // transaction 1. The first attempts fails when writing the POST data. |
| 8589 | // This causes the transaction to retry with a new socket. The second |
| 8590 | // attempt succeeds. |
| 8591 | request[1].method = "POST"; |
| 8592 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8593 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8594 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8595 | request[1].traffic_annotation = |
| 8596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8599 | |
| 8600 | // The first socket is used for transaction 1 and the first attempt of |
| 8601 | // transaction 2. |
| 8602 | |
| 8603 | // The response of transaction 1. |
| 8604 | MockRead data_reads1[] = { |
| 8605 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8606 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8608 | }; |
| 8609 | // The mock write results of transaction 1 and the first attempt of |
| 8610 | // transaction 2. |
| 8611 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8612 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8613 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8614 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8615 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8616 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8617 | |
| 8618 | // The second socket is used for the second attempt of transaction 2. |
| 8619 | |
| 8620 | // The response of transaction 2. |
| 8621 | MockRead data_reads2[] = { |
| 8622 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8623 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8624 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8625 | }; |
| 8626 | // The mock write results of the second attempt of transaction 2. |
| 8627 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8628 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8629 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8630 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8631 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8632 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8633 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8635 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8636 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8637 | "hello world", "welcome" |
| 8638 | }; |
| 8639 | |
| 8640 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8643 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8645 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8647 | |
| 8648 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8649 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8652 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8653 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8654 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8655 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8656 | |
| 8657 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8658 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8660 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8661 | } |
| 8662 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8663 | |
| 8664 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8665 | // 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] | 8666 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8667 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8668 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8670 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8671 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8672 | request.traffic_annotation = |
| 8673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8677 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8678 | // The password contains an escaped character -- for this test to pass it |
| 8679 | // will need to be unescaped by HttpNetworkTransaction. |
| 8680 | EXPECT_EQ("b%40r", request.url.password()); |
| 8681 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8682 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8683 | MockWrite( |
| 8684 | "GET / HTTP/1.1\r\n" |
| 8685 | "Host: www.example.org\r\n" |
| 8686 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8687 | }; |
| 8688 | |
| 8689 | MockRead data_reads1[] = { |
| 8690 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8691 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8692 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8693 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8694 | }; |
| 8695 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8696 | // After the challenge above, the transaction will be restarted using the |
| 8697 | // identity from the url (foo, b@r) to answer the challenge. |
| 8698 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8699 | MockWrite( |
| 8700 | "GET / HTTP/1.1\r\n" |
| 8701 | "Host: www.example.org\r\n" |
| 8702 | "Connection: keep-alive\r\n" |
| 8703 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8704 | }; |
| 8705 | |
| 8706 | MockRead data_reads2[] = { |
| 8707 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8708 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8709 | MockRead(SYNCHRONOUS, OK), |
| 8710 | }; |
| 8711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8712 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8713 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8714 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8715 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8716 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8717 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8718 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8720 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8721 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8722 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8723 | |
| 8724 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8725 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8727 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8728 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8729 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8731 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8732 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8733 | |
| 8734 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8735 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8736 | |
| 8737 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8738 | |
| 8739 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8740 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8744 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8745 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8746 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8747 | HttpRequestInfo request; |
| 8748 | request.method = "GET"; |
| 8749 | // Note: the URL has a username:password in it. The password "baz" is |
| 8750 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8751 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8752 | |
| 8753 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8754 | request.traffic_annotation = |
| 8755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8756 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8759 | |
| 8760 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8761 | MockWrite( |
| 8762 | "GET / HTTP/1.1\r\n" |
| 8763 | "Host: www.example.org\r\n" |
| 8764 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8765 | }; |
| 8766 | |
| 8767 | MockRead data_reads1[] = { |
| 8768 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8769 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8770 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8771 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8772 | }; |
| 8773 | |
| 8774 | // After the challenge above, the transaction will be restarted using the |
| 8775 | // identity from the url (foo, baz) to answer the challenge. |
| 8776 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8777 | MockWrite( |
| 8778 | "GET / HTTP/1.1\r\n" |
| 8779 | "Host: www.example.org\r\n" |
| 8780 | "Connection: keep-alive\r\n" |
| 8781 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8782 | }; |
| 8783 | |
| 8784 | MockRead data_reads2[] = { |
| 8785 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8786 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8787 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8788 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8789 | }; |
| 8790 | |
| 8791 | // After the challenge above, the transaction will be restarted using the |
| 8792 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8793 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8794 | MockWrite( |
| 8795 | "GET / HTTP/1.1\r\n" |
| 8796 | "Host: www.example.org\r\n" |
| 8797 | "Connection: keep-alive\r\n" |
| 8798 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8799 | }; |
| 8800 | |
| 8801 | MockRead data_reads3[] = { |
| 8802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8803 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8804 | MockRead(SYNCHRONOUS, OK), |
| 8805 | }; |
| 8806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8807 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8808 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8809 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8810 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8811 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8812 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8813 | |
| 8814 | TestCompletionCallback callback1; |
| 8815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8816 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8818 | |
| 8819 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8820 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8822 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8823 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8824 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8826 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8827 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8828 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8830 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8831 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8832 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8833 | |
| 8834 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8835 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8837 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8838 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8839 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8841 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8842 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8843 | |
| 8844 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8845 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8846 | |
| 8847 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8848 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8849 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8850 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8851 | } |
| 8852 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8853 | |
| 8854 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8855 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8856 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8857 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8858 | HttpRequestInfo request; |
| 8859 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8860 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8861 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8862 | request.traffic_annotation = |
| 8863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8867 | |
| 8868 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8869 | MockWrite( |
| 8870 | "GET / HTTP/1.1\r\n" |
| 8871 | "Host: www.example.org\r\n" |
| 8872 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8873 | }; |
| 8874 | |
| 8875 | MockRead data_reads1[] = { |
| 8876 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8877 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8878 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8879 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8880 | }; |
| 8881 | |
| 8882 | // After the challenge above, the transaction will be restarted using the |
| 8883 | // identity supplied by the user, not the one in the URL, to answer the |
| 8884 | // challenge. |
| 8885 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8886 | MockWrite( |
| 8887 | "GET / HTTP/1.1\r\n" |
| 8888 | "Host: www.example.org\r\n" |
| 8889 | "Connection: keep-alive\r\n" |
| 8890 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8891 | }; |
| 8892 | |
| 8893 | MockRead data_reads3[] = { |
| 8894 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8895 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8896 | MockRead(SYNCHRONOUS, OK), |
| 8897 | }; |
| 8898 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8899 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8900 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8901 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8902 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8903 | |
| 8904 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8905 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8908 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8909 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8912 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8913 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8914 | |
| 8915 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8916 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8918 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8919 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8920 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8922 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8923 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8924 | |
| 8925 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8926 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8927 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8928 | |
| 8929 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8930 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8931 | } |
| 8932 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8933 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8934 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8936 | |
| 8937 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8938 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8939 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8941 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8942 | request.traffic_annotation = |
| 8943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8946 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8947 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8948 | MockWrite( |
| 8949 | "GET /x/y/z HTTP/1.1\r\n" |
| 8950 | "Host: www.example.org\r\n" |
| 8951 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8952 | }; |
| 8953 | |
| 8954 | MockRead data_reads1[] = { |
| 8955 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8956 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8957 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8958 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8959 | }; |
| 8960 | |
| 8961 | // Resend with authorization (username=foo, password=bar) |
| 8962 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8963 | MockWrite( |
| 8964 | "GET /x/y/z HTTP/1.1\r\n" |
| 8965 | "Host: www.example.org\r\n" |
| 8966 | "Connection: keep-alive\r\n" |
| 8967 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8968 | }; |
| 8969 | |
| 8970 | // Sever accepts the authorization. |
| 8971 | MockRead data_reads2[] = { |
| 8972 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8973 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8974 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8975 | }; |
| 8976 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8977 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8978 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8979 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8980 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8981 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8982 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8984 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8986 | |
| 8987 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8988 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8990 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8991 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8992 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8994 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8996 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8997 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8999 | |
| 9000 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9001 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9003 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9004 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9005 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9006 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9007 | } |
| 9008 | |
| 9009 | // ------------------------------------------------------------------------ |
| 9010 | |
| 9011 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 9012 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9013 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9014 | request.method = "GET"; |
| 9015 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9016 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9017 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9018 | request.traffic_annotation = |
| 9019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9022 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9023 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9024 | MockWrite( |
| 9025 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9026 | "Host: www.example.org\r\n" |
| 9027 | "Connection: keep-alive\r\n" |
| 9028 | // Send preemptive authorization for MyRealm1 |
| 9029 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9030 | }; |
| 9031 | |
| 9032 | // The server didn't like the preemptive authorization, and |
| 9033 | // challenges us for a different realm (MyRealm2). |
| 9034 | MockRead data_reads1[] = { |
| 9035 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9036 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 9037 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9038 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9039 | }; |
| 9040 | |
| 9041 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 9042 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9043 | MockWrite( |
| 9044 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9045 | "Host: www.example.org\r\n" |
| 9046 | "Connection: keep-alive\r\n" |
| 9047 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9048 | }; |
| 9049 | |
| 9050 | // Sever accepts the authorization. |
| 9051 | MockRead data_reads2[] = { |
| 9052 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9053 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9054 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9055 | }; |
| 9056 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9057 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9058 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9060 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9062 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9064 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9066 | |
| 9067 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9068 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9070 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9071 | ASSERT_TRUE(response); |
| 9072 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9073 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9074 | EXPECT_EQ("http://www.example.org", |
| 9075 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9076 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9077 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9079 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9080 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9081 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 9082 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9084 | |
| 9085 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9088 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9089 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9090 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9092 | } |
| 9093 | |
| 9094 | // ------------------------------------------------------------------------ |
| 9095 | |
| 9096 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 9097 | // succeed with preemptive authorization. |
| 9098 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9099 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9100 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9101 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9102 | request.traffic_annotation = |
| 9103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9106 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9107 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9108 | MockWrite( |
| 9109 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 9110 | "Host: www.example.org\r\n" |
| 9111 | "Connection: keep-alive\r\n" |
| 9112 | // The authorization for MyRealm1 gets sent preemptively |
| 9113 | // (since the url is in the same protection space) |
| 9114 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9115 | }; |
| 9116 | |
| 9117 | // Sever accepts the preemptive authorization |
| 9118 | MockRead data_reads1[] = { |
| 9119 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9120 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9121 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9122 | }; |
| 9123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9124 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9125 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9127 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9129 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9131 | |
| 9132 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9136 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9137 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9138 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9139 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9140 | } |
| 9141 | |
| 9142 | // ------------------------------------------------------------------------ |
| 9143 | |
| 9144 | // Transaction 4: request another URL in MyRealm (however the |
| 9145 | // url is not known to belong to the protection space, so no pre-auth). |
| 9146 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9147 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9148 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9149 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9150 | request.traffic_annotation = |
| 9151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9153 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9154 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9155 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9156 | MockWrite( |
| 9157 | "GET /x/1 HTTP/1.1\r\n" |
| 9158 | "Host: www.example.org\r\n" |
| 9159 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9160 | }; |
| 9161 | |
| 9162 | MockRead data_reads1[] = { |
| 9163 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9164 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9165 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9166 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9167 | }; |
| 9168 | |
| 9169 | // Resend with authorization from MyRealm's cache. |
| 9170 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9171 | MockWrite( |
| 9172 | "GET /x/1 HTTP/1.1\r\n" |
| 9173 | "Host: www.example.org\r\n" |
| 9174 | "Connection: keep-alive\r\n" |
| 9175 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9176 | }; |
| 9177 | |
| 9178 | // Sever accepts the authorization. |
| 9179 | MockRead data_reads2[] = { |
| 9180 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9181 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9182 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9183 | }; |
| 9184 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9185 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9186 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9187 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9188 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9190 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9191 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9192 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9194 | |
| 9195 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9196 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9198 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9199 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9200 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9202 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9204 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9206 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9207 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9208 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9209 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9210 | } |
| 9211 | |
| 9212 | // ------------------------------------------------------------------------ |
| 9213 | |
| 9214 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9215 | // cached identity. Should invalidate and re-prompt. |
| 9216 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9217 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9218 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9219 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9220 | request.traffic_annotation = |
| 9221 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9224 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9225 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9226 | MockWrite( |
| 9227 | "GET /p/q/t HTTP/1.1\r\n" |
| 9228 | "Host: www.example.org\r\n" |
| 9229 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9230 | }; |
| 9231 | |
| 9232 | MockRead data_reads1[] = { |
| 9233 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9234 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9235 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9236 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9237 | }; |
| 9238 | |
| 9239 | // Resend with authorization from cache for MyRealm. |
| 9240 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9241 | MockWrite( |
| 9242 | "GET /p/q/t HTTP/1.1\r\n" |
| 9243 | "Host: www.example.org\r\n" |
| 9244 | "Connection: keep-alive\r\n" |
| 9245 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9246 | }; |
| 9247 | |
| 9248 | // Sever rejects the authorization. |
| 9249 | MockRead data_reads2[] = { |
| 9250 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9251 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9252 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9253 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9254 | }; |
| 9255 | |
| 9256 | // At this point we should prompt for new credentials for MyRealm. |
| 9257 | // Restart with username=foo3, password=foo4. |
| 9258 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9259 | MockWrite( |
| 9260 | "GET /p/q/t HTTP/1.1\r\n" |
| 9261 | "Host: www.example.org\r\n" |
| 9262 | "Connection: keep-alive\r\n" |
| 9263 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9264 | }; |
| 9265 | |
| 9266 | // Sever accepts the authorization. |
| 9267 | MockRead data_reads3[] = { |
| 9268 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9269 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9270 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9271 | }; |
| 9272 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9273 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9274 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9275 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9276 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9277 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9278 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9280 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9281 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9282 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9284 | |
| 9285 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9286 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9288 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9289 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9292 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9293 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9294 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9296 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9297 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9298 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9299 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9300 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9302 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9303 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9305 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9306 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9309 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9310 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9311 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9312 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9313 | } |
| 9314 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9315 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9316 | // Tests that nonce count increments when multiple auth attempts |
| 9317 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9318 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9319 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9320 | new HttpAuthHandlerDigest::Factory(); |
| 9321 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9322 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9323 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9324 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9326 | |
| 9327 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9328 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9329 | HttpRequestInfo request; |
| 9330 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9331 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9332 | request.traffic_annotation = |
| 9333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9334 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9335 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9336 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9337 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9338 | MockWrite( |
| 9339 | "GET /x/y/z HTTP/1.1\r\n" |
| 9340 | "Host: www.example.org\r\n" |
| 9341 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9342 | }; |
| 9343 | |
| 9344 | MockRead data_reads1[] = { |
| 9345 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9346 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9347 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9348 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9349 | }; |
| 9350 | |
| 9351 | // Resend with authorization (username=foo, password=bar) |
| 9352 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9353 | MockWrite( |
| 9354 | "GET /x/y/z HTTP/1.1\r\n" |
| 9355 | "Host: www.example.org\r\n" |
| 9356 | "Connection: keep-alive\r\n" |
| 9357 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9358 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9359 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9360 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9361 | }; |
| 9362 | |
| 9363 | // Sever accepts the authorization. |
| 9364 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9365 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9366 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9367 | }; |
| 9368 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9369 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9370 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9371 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9373 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9374 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9375 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9376 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9378 | |
| 9379 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9382 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9383 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9384 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9386 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9388 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9389 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9391 | |
| 9392 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9393 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9395 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9396 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9397 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9398 | } |
| 9399 | |
| 9400 | // ------------------------------------------------------------------------ |
| 9401 | |
| 9402 | // Transaction 2: Request another resource in digestive's protection space. |
| 9403 | // This will preemptively add an Authorization header which should have an |
| 9404 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9405 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9406 | HttpRequestInfo request; |
| 9407 | request.method = "GET"; |
| 9408 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9409 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9410 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9411 | request.traffic_annotation = |
| 9412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9415 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9416 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9417 | MockWrite( |
| 9418 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9419 | "Host: www.example.org\r\n" |
| 9420 | "Connection: keep-alive\r\n" |
| 9421 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9422 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9423 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9424 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9425 | }; |
| 9426 | |
| 9427 | // Sever accepts the authorization. |
| 9428 | MockRead data_reads1[] = { |
| 9429 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9430 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9432 | }; |
| 9433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9434 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9435 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9437 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9438 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9439 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9441 | |
| 9442 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9445 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9446 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9447 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9448 | } |
| 9449 | } |
| 9450 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9451 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9452 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9453 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9455 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9456 | |
| 9457 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9458 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9459 | trans.read_buf_len_ = 15; |
| 9460 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9461 | |
| 9462 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9463 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9464 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9465 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9466 | response->response_time = base::Time::Now(); |
| 9467 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9468 | |
| 9469 | { // Setup state for response_.vary_data |
| 9470 | HttpRequestInfo request; |
| 9471 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9472 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9473 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9474 | request.extra_headers.SetHeader("Foo", "1"); |
| 9475 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9476 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9477 | } |
| 9478 | |
| 9479 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9480 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9481 | |
| 9482 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9483 | EXPECT_FALSE(trans.read_buf_); |
| 9484 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9485 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9486 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9487 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9488 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9489 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9490 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9491 | } |
| 9492 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9493 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9494 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9495 | HttpRequestInfo request; |
| 9496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9497 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9498 | request.traffic_annotation = |
| 9499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9500 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9503 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9504 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9505 | MockWrite( |
| 9506 | "GET / HTTP/1.1\r\n" |
| 9507 | "Host: www.example.org\r\n" |
| 9508 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9509 | }; |
| 9510 | |
| 9511 | MockRead data_reads[] = { |
| 9512 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9513 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9514 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9515 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9516 | }; |
| 9517 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9518 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9519 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9520 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9521 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9522 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9523 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9525 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9528 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9532 | |
| 9533 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9534 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9536 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9538 | |
| 9539 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9542 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9543 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9544 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9545 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9546 | } |
| 9547 | |
| 9548 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9549 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9550 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9551 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9552 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9553 | |
| 9554 | HttpRequestInfo request; |
| 9555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9556 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9557 | request.traffic_annotation = |
| 9558 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9559 | |
| 9560 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9561 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9562 | "Host: www.example.org:443\r\n" |
| 9563 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9564 | }; |
| 9565 | |
| 9566 | MockRead proxy_reads[] = { |
| 9567 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9568 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9569 | }; |
| 9570 | |
| 9571 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9572 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9573 | "Host: www.example.org:443\r\n" |
| 9574 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9575 | MockWrite("GET / HTTP/1.1\r\n" |
| 9576 | "Host: www.example.org\r\n" |
| 9577 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9578 | }; |
| 9579 | |
| 9580 | MockRead data_reads[] = { |
| 9581 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9582 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9583 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9584 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9585 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9586 | }; |
| 9587 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9588 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9589 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9590 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9591 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9592 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9593 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9596 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9598 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9599 | |
| 9600 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9601 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9605 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9606 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9607 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9608 | |
| 9609 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9610 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9612 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9614 | |
| 9615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9618 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9619 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9620 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9621 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9622 | } |
| 9623 | } |
| 9624 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9625 | |
| 9626 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9627 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9628 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9629 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9630 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9631 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9632 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9633 | |
| 9634 | HttpRequestInfo request; |
| 9635 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9636 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9637 | request.traffic_annotation = |
| 9638 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9639 | |
| 9640 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9641 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9642 | "Host: www.example.org:443\r\n" |
| 9643 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9644 | MockWrite("GET / HTTP/1.1\r\n" |
| 9645 | "Host: www.example.org\r\n" |
| 9646 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9647 | }; |
| 9648 | |
| 9649 | MockRead data_reads[] = { |
| 9650 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9651 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9652 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9653 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9654 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9655 | }; |
| 9656 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9657 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9658 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9659 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9660 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9664 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9665 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9666 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9668 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9672 | |
| 9673 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9674 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9676 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9677 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9678 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9679 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9680 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9681 | EXPECT_EQ(200, response->headers->response_code()); |
| 9682 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9683 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9684 | |
| 9685 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9686 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9687 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9688 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9689 | } |
| 9690 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9691 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9692 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9693 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9694 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9695 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9696 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9697 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9698 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9699 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9700 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9701 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9702 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9703 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9704 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9705 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9706 | request.traffic_annotation = |
| 9707 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9708 | |
| 9709 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9710 | MockWrite(ASYNC, 0, |
| 9711 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9712 | "Host: www.example.org:443\r\n" |
| 9713 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9714 | }; |
| 9715 | |
| 9716 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9717 | // Pause on first read. |
| 9718 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9719 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9720 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9721 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9722 | }; |
| 9723 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9724 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9725 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9726 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9727 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9730 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9734 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9735 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9737 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9738 | |
| 9739 | // Host resolution takes |kTimeIncrement|. |
| 9740 | FastForwardBy(kTimeIncrement); |
| 9741 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9742 | // request to instantly complete, and the async connect will start as well. |
| 9743 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9744 | |
| 9745 | // Connecting takes |kTimeIncrement|. |
| 9746 | FastForwardBy(kTimeIncrement); |
| 9747 | data.RunUntilPaused(); |
| 9748 | |
| 9749 | // The server takes |kTimeIncrement| to respond. |
| 9750 | FastForwardBy(kTimeIncrement); |
| 9751 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9752 | |
| 9753 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9754 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9755 | } |
| 9756 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9757 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9758 | TEST_F(HttpNetworkTransactionTest, |
| 9759 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9760 | base::HistogramTester histograms; |
| 9761 | session_deps_.proxy_resolution_service = |
| 9762 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9763 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9764 | TestNetLog net_log; |
| 9765 | session_deps_.net_log = &net_log; |
| 9766 | |
| 9767 | HttpRequestInfo request; |
| 9768 | request.method = "GET"; |
| 9769 | request.url = GURL("https://www.example.org/"); |
| 9770 | request.traffic_annotation = |
| 9771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9772 | |
| 9773 | MockWrite data_writes[] = { |
| 9774 | MockWrite(ASYNC, 0, |
| 9775 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9776 | "Host: www.example.org:443\r\n" |
| 9777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9778 | }; |
| 9779 | |
| 9780 | MockRead data_reads[] = { |
| 9781 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9782 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9783 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9784 | }; |
| 9785 | |
| 9786 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9787 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9788 | |
| 9789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9790 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9791 | |
| 9792 | TestCompletionCallback callback; |
| 9793 | |
| 9794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9796 | |
| 9797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9799 | |
| 9800 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9801 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9802 | } |
| 9803 | |
| 9804 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9805 | // request for main frames. |
| 9806 | TEST_F(HttpNetworkTransactionTest, |
| 9807 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9808 | base::HistogramTester histograms; |
| 9809 | session_deps_.proxy_resolution_service = |
| 9810 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9811 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9812 | TestNetLog net_log; |
| 9813 | session_deps_.net_log = &net_log; |
| 9814 | |
| 9815 | HttpRequestInfo request; |
| 9816 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9817 | request.method = "GET"; |
| 9818 | request.url = GURL("https://www.example.org/"); |
| 9819 | request.traffic_annotation = |
| 9820 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9821 | |
| 9822 | MockWrite data_writes[] = { |
| 9823 | MockWrite(ASYNC, 0, |
| 9824 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9825 | "Host: www.example.org:443\r\n" |
| 9826 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9827 | }; |
| 9828 | |
| 9829 | MockRead data_reads[] = { |
| 9830 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9831 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9832 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9833 | }; |
| 9834 | |
| 9835 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9836 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9837 | |
| 9838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9839 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9840 | |
| 9841 | TestCompletionCallback callback; |
| 9842 | |
| 9843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9845 | |
| 9846 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9848 | |
| 9849 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9850 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9851 | } |
| 9852 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9853 | // 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] | 9854 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9855 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9856 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9857 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9858 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9859 | TestNetLog net_log; |
| 9860 | session_deps_.net_log = &net_log; |
| 9861 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9862 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9863 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9864 | |
| 9865 | HttpRequestInfo request; |
| 9866 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9867 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9868 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9869 | request.traffic_annotation = |
| 9870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9871 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9872 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9873 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9874 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9875 | spdy::SpdySerializedFrame goaway( |
| 9876 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9877 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9878 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9879 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9880 | }; |
| 9881 | |
| 9882 | static const char* const kExtraHeaders[] = { |
| 9883 | "location", |
| 9884 | "http://login.example.com/", |
| 9885 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9886 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9887 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9888 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9889 | // Pause on first read. |
| 9890 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9891 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9892 | }; |
| 9893 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9894 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9895 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9896 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9897 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9901 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9906 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9908 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9909 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9910 | // Host resolution takes |kTimeIncrement|. |
| 9911 | FastForwardBy(kTimeIncrement); |
| 9912 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9913 | // request to instantly complete, and the async connect will start as well. |
| 9914 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9915 | |
| 9916 | // Connecting takes |kTimeIncrement|. |
| 9917 | FastForwardBy(kTimeIncrement); |
| 9918 | data.RunUntilPaused(); |
| 9919 | |
| 9920 | FastForwardBy(kTimeIncrement); |
| 9921 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9922 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9923 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9924 | } |
| 9925 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9926 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9927 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9928 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9929 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9930 | |
| 9931 | HttpRequestInfo request; |
| 9932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9933 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9934 | request.traffic_annotation = |
| 9935 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9936 | |
| 9937 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9938 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9939 | "Host: www.example.org:443\r\n" |
| 9940 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9941 | }; |
| 9942 | |
| 9943 | MockRead data_reads[] = { |
| 9944 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9945 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9946 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9948 | }; |
| 9949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9950 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9951 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9952 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9953 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9956 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9957 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9959 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9960 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9961 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9963 | |
| 9964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9965 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9966 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9967 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9968 | } |
| 9969 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9970 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9971 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9972 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9973 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9974 | |
| 9975 | HttpRequestInfo request; |
| 9976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9977 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9978 | request.traffic_annotation = |
| 9979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9980 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9981 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9982 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9983 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9984 | spdy::SpdySerializedFrame rst( |
| 9985 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9986 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9987 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9988 | }; |
| 9989 | |
| 9990 | static const char* const kExtraHeaders[] = { |
| 9991 | "location", |
| 9992 | "http://login.example.com/", |
| 9993 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9994 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9995 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9996 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9997 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9998 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9999 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10000 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10001 | }; |
| 10002 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10003 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10004 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10005 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10006 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10007 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10010 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10011 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10013 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10014 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10015 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10017 | |
| 10018 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10019 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10020 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 10021 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10022 | } |
| 10023 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10024 | // Test the request-challenge-retry sequence for basic auth, through |
| 10025 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10026 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10027 | HttpRequestInfo request; |
| 10028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10029 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10030 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 10031 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10032 | request.traffic_annotation = |
| 10033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10034 | |
| 10035 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10036 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10037 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10038 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10039 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10040 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10042 | |
| 10043 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10044 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10045 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10046 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10047 | spdy::SpdySerializedFrame rst( |
| 10048 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10049 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10051 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10052 | // be issuing -- the final header line contains the credentials. |
| 10053 | const char* const kAuthCredentials[] = { |
| 10054 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 10055 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10056 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10057 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 10058 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10059 | HostPortPair("www.example.org", 443))); |
| 10060 | // fetch https://www.example.org/ via HTTP |
| 10061 | const char get[] = |
| 10062 | "GET / HTTP/1.1\r\n" |
| 10063 | "Host: www.example.org\r\n" |
| 10064 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10065 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10066 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10067 | |
| 10068 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10069 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 10070 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10071 | }; |
| 10072 | |
| 10073 | // The proxy responds to the connect with a 407, using a persistent |
| 10074 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10075 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10076 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10077 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 10078 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10079 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10080 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10081 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10082 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10083 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10084 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 10085 | "Content-Length: 5\r\n\r\n"; |
| 10086 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10087 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10088 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10089 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10090 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10091 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10092 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10093 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10094 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10095 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10096 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10097 | }; |
| 10098 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10099 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10100 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10101 | // Negotiate SPDY to the proxy |
| 10102 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10103 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10104 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10105 | // Vanilla SSL to the server |
| 10106 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10107 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10108 | |
| 10109 | TestCompletionCallback callback1; |
| 10110 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10111 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10112 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10113 | |
| 10114 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10116 | |
| 10117 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10118 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 10119 | auto entries = log.GetEntries(); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10120 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10121 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10122 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10123 | ExpectLogContainsSomewhere( |
| 10124 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10125 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10126 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10127 | |
| 10128 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10129 | ASSERT_TRUE(response); |
| 10130 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10131 | EXPECT_EQ(407, response->headers->response_code()); |
| 10132 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10133 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 10134 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10135 | |
| 10136 | TestCompletionCallback callback2; |
| 10137 | |
| 10138 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10139 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10141 | |
| 10142 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10143 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10144 | |
| 10145 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10146 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10147 | |
| 10148 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10149 | EXPECT_EQ(200, response->headers->response_code()); |
| 10150 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10151 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10152 | |
| 10153 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10154 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10155 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10156 | LoadTimingInfo load_timing_info; |
| 10157 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10158 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10159 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10160 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10161 | trans.reset(); |
| 10162 | session->CloseAllConnections(); |
| 10163 | } |
| 10164 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10165 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10166 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10167 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10168 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10169 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10170 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10171 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10172 | HttpRequestInfo request; |
| 10173 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10174 | request.traffic_annotation = |
| 10175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10176 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10177 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10178 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10179 | push_request.method = "GET"; |
| 10180 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10181 | push_request.traffic_annotation = |
| 10182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10183 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10184 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10185 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10186 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10187 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10188 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10189 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10190 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10191 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10192 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10193 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10195 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10196 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10197 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10198 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10199 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10200 | |
| 10201 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10202 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10203 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10204 | }; |
| 10205 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10206 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10207 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10208 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10209 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10210 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10211 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10212 | spdy::SpdySerializedFrame stream1_body( |
| 10213 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10214 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10215 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10216 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10217 | |
| 10218 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10219 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10220 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10221 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10222 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10223 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10224 | }; |
| 10225 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10226 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10227 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10228 | // Negotiate SPDY to the proxy |
| 10229 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10230 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10232 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10233 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10234 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10235 | TestCompletionCallback callback; |
| 10236 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10237 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10238 | |
| 10239 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10241 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10242 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10243 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10244 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10245 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10247 | |
| 10248 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10250 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10251 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10252 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10253 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10254 | |
| 10255 | EXPECT_EQ(200, response->headers->response_code()); |
| 10256 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10257 | |
| 10258 | std::string response_data; |
| 10259 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10261 | EXPECT_EQ("hello!", response_data); |
| 10262 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10263 | LoadTimingInfo load_timing_info; |
| 10264 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10265 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10266 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10267 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10268 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10269 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10270 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10271 | |
| 10272 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10274 | EXPECT_EQ("pushed", response_data); |
| 10275 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10276 | LoadTimingInfo push_load_timing_info; |
| 10277 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10278 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10279 | // The transactions should share a socket ID, despite being for different |
| 10280 | // origins. |
| 10281 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10282 | push_load_timing_info.socket_log_id); |
| 10283 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10284 | trans.reset(); |
| 10285 | push_trans.reset(); |
| 10286 | session->CloseAllConnections(); |
| 10287 | } |
| 10288 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10289 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10290 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10291 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10292 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10293 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10294 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10295 | HttpRequestInfo request; |
| 10296 | |
| 10297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10298 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10299 | request.traffic_annotation = |
| 10300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10301 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10302 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10303 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10304 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10305 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10306 | |
| 10307 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10308 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10309 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10312 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10313 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10314 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10315 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10316 | spdy::SpdySerializedFrame push_rst( |
| 10317 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10318 | |
| 10319 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10320 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10321 | }; |
| 10322 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10323 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10324 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10325 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10326 | spdy::SpdySerializedFrame stream1_body( |
| 10327 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10328 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10329 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10330 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10331 | |
| 10332 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10333 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10334 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10335 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10336 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10337 | }; |
| 10338 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10339 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10340 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10341 | // Negotiate SPDY to the proxy |
| 10342 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10343 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10344 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10345 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10346 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10347 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10348 | TestCompletionCallback callback; |
| 10349 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10350 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10351 | |
| 10352 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10353 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10354 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10355 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10356 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10357 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10358 | |
| 10359 | EXPECT_EQ(200, response->headers->response_code()); |
| 10360 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10361 | |
| 10362 | std::string response_data; |
| 10363 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10365 | EXPECT_EQ("hello!", response_data); |
| 10366 | |
| 10367 | trans.reset(); |
| 10368 | session->CloseAllConnections(); |
| 10369 | } |
| 10370 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10371 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10372 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10373 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10374 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10375 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10376 | proxy_delegate->set_trusted_spdy_proxy( |
| 10377 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10378 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10379 | HttpRequestInfo request; |
| 10380 | |
| 10381 | request.method = "GET"; |
| 10382 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10383 | request.traffic_annotation = |
| 10384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10385 | |
| 10386 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10387 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10388 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10389 | BoundTestNetLog log; |
| 10390 | session_deps_.net_log = log.bound().net_log(); |
| 10391 | |
| 10392 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10393 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10394 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10395 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10397 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10398 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10399 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10400 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10401 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10402 | |
| 10403 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10404 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10405 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10406 | }; |
| 10407 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10408 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10409 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10410 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10411 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10412 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10413 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10414 | spdy::SpdySerializedFrame stream1_body( |
| 10415 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10416 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10417 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10418 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10419 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10420 | spdy::SpdySerializedFrame stream2_body( |
| 10421 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10422 | |
| 10423 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10424 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10425 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10426 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10427 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10428 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10429 | }; |
| 10430 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10431 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10432 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10433 | // Negotiate SPDY to the proxy |
| 10434 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10435 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10437 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10438 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10439 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10440 | TestCompletionCallback callback; |
| 10441 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10443 | |
| 10444 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10445 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10446 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10447 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10448 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10449 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10450 | |
| 10451 | EXPECT_EQ(200, response->headers->response_code()); |
| 10452 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10453 | |
| 10454 | std::string response_data; |
| 10455 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10456 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10457 | EXPECT_EQ("hello!", response_data); |
| 10458 | |
| 10459 | trans.reset(); |
| 10460 | session->CloseAllConnections(); |
| 10461 | } |
| 10462 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10463 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10464 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10465 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10466 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10467 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10468 | |
| 10469 | HttpRequestInfo request; |
| 10470 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10471 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10472 | request.traffic_annotation = |
| 10473 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10474 | |
| 10475 | // Attempt to fetch the URL from a server with a bad cert |
| 10476 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10477 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10478 | "Host: www.example.org:443\r\n" |
| 10479 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10480 | }; |
| 10481 | |
| 10482 | MockRead bad_cert_reads[] = { |
| 10483 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10484 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10485 | }; |
| 10486 | |
| 10487 | // Attempt to fetch the URL with a good cert |
| 10488 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10489 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10490 | "Host: www.example.org:443\r\n" |
| 10491 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10492 | MockWrite("GET / HTTP/1.1\r\n" |
| 10493 | "Host: www.example.org\r\n" |
| 10494 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10495 | }; |
| 10496 | |
| 10497 | MockRead good_cert_reads[] = { |
| 10498 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10499 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10500 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10501 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10502 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10503 | }; |
| 10504 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10505 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10506 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10507 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10508 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10509 | |
| 10510 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10512 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10514 | |
| 10515 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10517 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10520 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10521 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10524 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10525 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10527 | |
| 10528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10529 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10531 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10533 | |
| 10534 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10535 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10537 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10538 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10539 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10540 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10541 | } |
| 10542 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10543 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10544 | HttpRequestInfo request; |
| 10545 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10546 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10547 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10548 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10549 | request.traffic_annotation = |
| 10550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10554 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10555 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10556 | MockWrite( |
| 10557 | "GET / HTTP/1.1\r\n" |
| 10558 | "Host: www.example.org\r\n" |
| 10559 | "Connection: keep-alive\r\n" |
| 10560 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10561 | }; |
| 10562 | |
| 10563 | // Lastly, the server responds with the actual content. |
| 10564 | MockRead data_reads[] = { |
| 10565 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10566 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10567 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10568 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10569 | }; |
| 10570 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10571 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10574 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10578 | |
| 10579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10581 | } |
| 10582 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10583 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10584 | // Test user agent values, used both for the request header of the original |
| 10585 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10586 | // no request header / no HttpUserAgentSettings object. |
| 10587 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10588 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10589 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10590 | if (!setting_user_agent) { |
| 10591 | session_deps_.http_user_agent_settings.reset(); |
| 10592 | } else { |
| 10593 | session_deps_.http_user_agent_settings = |
| 10594 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10595 | std::string() /* accept-language */, setting_user_agent); |
| 10596 | } |
| 10597 | session_deps_.proxy_resolution_service = |
| 10598 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10599 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10601 | for (const char* request_user_agent : kTestUserAgents) { |
| 10602 | HttpRequestInfo request; |
| 10603 | request.method = "GET"; |
| 10604 | request.url = GURL("https://www.example.org/"); |
| 10605 | if (request_user_agent) { |
| 10606 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10607 | request_user_agent); |
| 10608 | } |
| 10609 | request.traffic_annotation = |
| 10610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10611 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10613 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10614 | std::string expected_request; |
| 10615 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10616 | expected_request = |
| 10617 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10618 | "Host: www.example.org:443\r\n" |
| 10619 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10620 | } else { |
| 10621 | expected_request = base::StringPrintf( |
| 10622 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10623 | "Host: www.example.org:443\r\n" |
| 10624 | "Proxy-Connection: keep-alive\r\n" |
| 10625 | "User-Agent: %s\r\n\r\n", |
| 10626 | setting_user_agent); |
| 10627 | } |
| 10628 | MockWrite data_writes[] = { |
| 10629 | MockWrite(expected_request.c_str()), |
| 10630 | }; |
| 10631 | MockRead data_reads[] = { |
| 10632 | // Return an error, so the transaction stops here (this test isn't |
| 10633 | // interested in the rest). |
| 10634 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10635 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10636 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10637 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10638 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10639 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10641 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10642 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10643 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10646 | |
| 10647 | rv = callback.WaitForResult(); |
| 10648 | EXPECT_THAT(rv, IsOk()); |
| 10649 | } |
| 10650 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10651 | } |
| 10652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10653 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10654 | HttpRequestInfo request; |
| 10655 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10656 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10657 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10658 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10659 | request.traffic_annotation = |
| 10660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10664 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10665 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10666 | MockWrite( |
| 10667 | "GET / HTTP/1.1\r\n" |
| 10668 | "Host: www.example.org\r\n" |
| 10669 | "Connection: keep-alive\r\n" |
| 10670 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | }; |
| 10672 | |
| 10673 | // Lastly, the server responds with the actual content. |
| 10674 | MockRead data_reads[] = { |
| 10675 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10676 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10677 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10678 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10679 | }; |
| 10680 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10681 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10684 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10686 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10688 | |
| 10689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10691 | } |
| 10692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10693 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10694 | HttpRequestInfo request; |
| 10695 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10696 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10697 | request.traffic_annotation = |
| 10698 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10702 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10703 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10704 | MockWrite( |
| 10705 | "POST / HTTP/1.1\r\n" |
| 10706 | "Host: www.example.org\r\n" |
| 10707 | "Connection: keep-alive\r\n" |
| 10708 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10709 | }; |
| 10710 | |
| 10711 | // Lastly, the server responds with the actual content. |
| 10712 | MockRead data_reads[] = { |
| 10713 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10714 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10715 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10717 | }; |
| 10718 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10719 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10720 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10722 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10724 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10726 | |
| 10727 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10729 | } |
| 10730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10731 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10732 | HttpRequestInfo request; |
| 10733 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10734 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10735 | request.traffic_annotation = |
| 10736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10740 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10741 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10742 | MockWrite( |
| 10743 | "PUT / HTTP/1.1\r\n" |
| 10744 | "Host: www.example.org\r\n" |
| 10745 | "Connection: keep-alive\r\n" |
| 10746 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10747 | }; |
| 10748 | |
| 10749 | // Lastly, the server responds with the actual content. |
| 10750 | MockRead data_reads[] = { |
| 10751 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10753 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10755 | }; |
| 10756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10757 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10760 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10762 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10764 | |
| 10765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10767 | } |
| 10768 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10769 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10770 | HttpRequestInfo request; |
| 10771 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10772 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10773 | request.traffic_annotation = |
| 10774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10778 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10779 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10780 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10781 | "Host: www.example.org\r\n" |
| 10782 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10783 | }; |
| 10784 | |
| 10785 | // Lastly, the server responds with the actual content. |
| 10786 | MockRead data_reads[] = { |
| 10787 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10788 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10789 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10791 | }; |
| 10792 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10793 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10794 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10795 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10796 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10800 | |
| 10801 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10803 | } |
| 10804 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10805 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10806 | HttpRequestInfo request; |
| 10807 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10808 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10809 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10810 | request.traffic_annotation = |
| 10811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10815 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10816 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10817 | MockWrite( |
| 10818 | "GET / HTTP/1.1\r\n" |
| 10819 | "Host: www.example.org\r\n" |
| 10820 | "Connection: keep-alive\r\n" |
| 10821 | "Pragma: no-cache\r\n" |
| 10822 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10823 | }; |
| 10824 | |
| 10825 | // Lastly, the server responds with the actual content. |
| 10826 | MockRead data_reads[] = { |
| 10827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10829 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10830 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10831 | }; |
| 10832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10833 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10836 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10840 | |
| 10841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10843 | } |
| 10844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10845 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10846 | HttpRequestInfo request; |
| 10847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10848 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10849 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10850 | request.traffic_annotation = |
| 10851 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10855 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10856 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10857 | MockWrite( |
| 10858 | "GET / HTTP/1.1\r\n" |
| 10859 | "Host: www.example.org\r\n" |
| 10860 | "Connection: keep-alive\r\n" |
| 10861 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10862 | }; |
| 10863 | |
| 10864 | // Lastly, the server responds with the actual content. |
| 10865 | MockRead data_reads[] = { |
| 10866 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10867 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10868 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10869 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10870 | }; |
| 10871 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10872 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10873 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10875 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10877 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10879 | |
| 10880 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10881 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10882 | } |
| 10883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10884 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10885 | HttpRequestInfo request; |
| 10886 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10887 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10888 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10889 | request.traffic_annotation = |
| 10890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10891 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10893 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10894 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10895 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10896 | MockWrite( |
| 10897 | "GET / HTTP/1.1\r\n" |
| 10898 | "Host: www.example.org\r\n" |
| 10899 | "Connection: keep-alive\r\n" |
| 10900 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10901 | }; |
| 10902 | |
| 10903 | // Lastly, the server responds with the actual content. |
| 10904 | MockRead data_reads[] = { |
| 10905 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10906 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10907 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10908 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10909 | }; |
| 10910 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10911 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10914 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10915 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10916 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10918 | |
| 10919 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10921 | } |
| 10922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10923 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10924 | HttpRequestInfo request; |
| 10925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10926 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10927 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10928 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10929 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10930 | request.traffic_annotation = |
| 10931 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10932 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10933 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10934 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10935 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10936 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10937 | MockWrite( |
| 10938 | "GET / HTTP/1.1\r\n" |
| 10939 | "Host: www.example.org\r\n" |
| 10940 | "Connection: keep-alive\r\n" |
| 10941 | "referer: www.foo.com\r\n" |
| 10942 | "hEllo: Kitty\r\n" |
| 10943 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10944 | }; |
| 10945 | |
| 10946 | // Lastly, the server responds with the actual content. |
| 10947 | MockRead data_reads[] = { |
| 10948 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10949 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10950 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10951 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10952 | }; |
| 10953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10954 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10955 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10957 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10958 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10959 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10961 | |
| 10962 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10963 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10964 | } |
| 10965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10966 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10967 | HttpRequestInfo request; |
| 10968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10969 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10970 | request.traffic_annotation = |
| 10971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10972 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10973 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10974 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10975 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10976 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10977 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10981 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10982 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10983 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10984 | |
| 10985 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10986 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10987 | MockWrite("GET / HTTP/1.1\r\n" |
| 10988 | "Host: www.example.org\r\n" |
| 10989 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10990 | |
| 10991 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10992 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10993 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10994 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10995 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10996 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10997 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11000 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11004 | |
| 11005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11008 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11009 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11010 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11011 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11012 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11013 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11014 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11015 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11016 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11017 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11018 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11020 | EXPECT_EQ("Payload", response_text); |
| 11021 | } |
| 11022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11023 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11024 | HttpRequestInfo request; |
| 11025 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11026 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11027 | request.traffic_annotation = |
| 11028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11029 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11030 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11031 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11032 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11033 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11034 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11038 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11039 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 11040 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11041 | |
| 11042 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11043 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11044 | base::size(write_buffer)), |
| 11045 | MockWrite("GET / HTTP/1.1\r\n" |
| 11046 | "Host: www.example.org\r\n" |
| 11047 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11048 | |
| 11049 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11050 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 11051 | base::size(read_buffer)), |
| 11052 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11054 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11056 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11058 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11059 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11062 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11064 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11066 | |
| 11067 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11068 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11069 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11070 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11071 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11072 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11073 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11075 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11076 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11077 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11078 | |
| 11079 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11080 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11081 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11082 | EXPECT_EQ("Payload", response_text); |
| 11083 | } |
| 11084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11085 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11086 | HttpRequestInfo request; |
| 11087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11088 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11089 | request.traffic_annotation = |
| 11090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11091 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11092 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11093 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11094 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11095 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11096 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11098 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11099 | |
| 11100 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11101 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11102 | |
| 11103 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11104 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11105 | MockWrite("GET / HTTP/1.1\r\n" |
| 11106 | "Host: www.example.org\r\n" |
| 11107 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11108 | |
| 11109 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11110 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11111 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11112 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11113 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11114 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11115 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11116 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11117 | |
| 11118 | TestCompletionCallback callback; |
| 11119 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11120 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11121 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11122 | |
| 11123 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11124 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11127 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11128 | |
| 11129 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11130 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11131 | TestLoadTimingNotReused(load_timing_info, |
| 11132 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11133 | |
| 11134 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11135 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11137 | EXPECT_EQ("Payload", response_text); |
| 11138 | } |
| 11139 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11140 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11141 | HttpRequestInfo request; |
| 11142 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11143 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11144 | request.traffic_annotation = |
| 11145 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11146 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11147 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11148 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11149 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11150 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11151 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11155 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11156 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11157 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11158 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11159 | 0x05, // Version |
| 11160 | 0x01, // Command (CONNECT) |
| 11161 | 0x00, // Reserved. |
| 11162 | 0x03, // Address type (DOMAINNAME). |
| 11163 | 0x0F, // Length of domain (15) |
| 11164 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11165 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11166 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11167 | const char kSOCKS5OkResponse[] = |
| 11168 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11169 | |
| 11170 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11171 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11172 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11173 | MockWrite("GET / HTTP/1.1\r\n" |
| 11174 | "Host: www.example.org\r\n" |
| 11175 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11176 | |
| 11177 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11178 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11179 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11180 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11181 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11182 | MockRead("Payload"), |
| 11183 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11184 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11185 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11186 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11188 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11189 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11190 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11191 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11192 | |
| 11193 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11194 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11196 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11197 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11198 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11199 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11200 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11201 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11202 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11203 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11204 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11205 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11206 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11207 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11208 | EXPECT_EQ("Payload", response_text); |
| 11209 | } |
| 11210 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11211 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11212 | HttpRequestInfo request; |
| 11213 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11214 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11215 | request.traffic_annotation = |
| 11216 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11217 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11218 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11219 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11220 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11221 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11222 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11223 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11224 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11226 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11227 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11228 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11229 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11230 | 0x05, // Version |
| 11231 | 0x01, // Command (CONNECT) |
| 11232 | 0x00, // Reserved. |
| 11233 | 0x03, // Address type (DOMAINNAME). |
| 11234 | 0x0F, // Length of domain (15) |
| 11235 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11236 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11237 | }; |
| 11238 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11239 | const char kSOCKS5OkResponse[] = |
| 11240 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11241 | |
| 11242 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11243 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11244 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11245 | base::size(kSOCKS5OkRequest)), |
| 11246 | MockWrite("GET / HTTP/1.1\r\n" |
| 11247 | "Host: www.example.org\r\n" |
| 11248 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11249 | |
| 11250 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11251 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11252 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11253 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11254 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11255 | MockRead("Payload"), |
| 11256 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11257 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11258 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11259 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11260 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11261 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11264 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11265 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11266 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11268 | |
| 11269 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11272 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11273 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11274 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11275 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11276 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11277 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11278 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11279 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11280 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11281 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11282 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11284 | EXPECT_EQ("Payload", response_text); |
| 11285 | } |
| 11286 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11287 | namespace { |
| 11288 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11289 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11290 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11291 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11292 | std::string proxy_server; |
| 11293 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11294 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11295 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11296 | }; |
| 11297 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11298 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11299 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11301 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11302 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11303 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11304 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11305 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11306 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11307 | url::SchemeHostPort("https", "host.with.alternate", 443), |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 11308 | NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11309 | |
| 11310 | return session; |
| 11311 | } |
| 11312 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11313 | int GroupIdTransactionHelper(const std::string& url, |
| 11314 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11315 | HttpRequestInfo request; |
| 11316 | request.method = "GET"; |
| 11317 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11318 | request.traffic_annotation = |
| 11319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11321 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11323 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11324 | |
| 11325 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11326 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11327 | } |
| 11328 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11329 | } // namespace |
| 11330 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11331 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11332 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11333 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11334 | "", // unused |
| 11335 | "http://www.example.org/direct", |
| 11336 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11337 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11338 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11339 | NetworkIsolationKey(), |
| 11340 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11341 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11342 | }, |
| 11343 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11344 | "", // unused |
| 11345 | "http://[2001:1418:13:1::25]/direct", |
| 11346 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11347 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11348 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11349 | NetworkIsolationKey(), |
| 11350 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11351 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11352 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11353 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11354 | // SSL Tests |
| 11355 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11356 | "", // unused |
| 11357 | "https://www.example.org/direct_ssl", |
| 11358 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11359 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11360 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11361 | NetworkIsolationKey(), |
| 11362 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11363 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11364 | }, |
| 11365 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11366 | "", // unused |
| 11367 | "https://[2001:1418:13:1::25]/direct", |
| 11368 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11369 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11370 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11371 | NetworkIsolationKey(), |
| 11372 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11373 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11374 | }, |
| 11375 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11376 | "", // unused |
| 11377 | "https://host.with.alternate/direct", |
| 11378 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11379 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11380 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11381 | NetworkIsolationKey(), |
| 11382 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11383 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11384 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11385 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11386 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11387 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11388 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11389 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11390 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11391 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11392 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11393 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11394 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11395 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11396 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11397 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11398 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11399 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11400 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11401 | |
| 11402 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11403 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11404 | EXPECT_EQ(tests[i].expected_group_id, |
| 11405 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11406 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11407 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11408 | } |
| 11409 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11410 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11411 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11413 | "http_proxy", |
| 11414 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11415 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11416 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11417 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11418 | NetworkIsolationKey(), |
| 11419 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11420 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11421 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11422 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11423 | // SSL Tests |
| 11424 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11425 | "http_proxy", |
| 11426 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11427 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11428 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11429 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11430 | NetworkIsolationKey(), |
| 11431 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11432 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11433 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11435 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11436 | "http_proxy", |
| 11437 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11438 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11439 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11440 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11441 | NetworkIsolationKey(), |
| 11442 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11443 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11444 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11445 | }; |
| 11446 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11447 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11448 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11449 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11450 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11451 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11452 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11453 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11454 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11455 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11456 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11457 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11458 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11459 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11460 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11461 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11462 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11463 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11464 | |
| 11465 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11466 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11467 | EXPECT_EQ(tests[i].expected_group_id, |
| 11468 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11469 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11470 | } |
| 11471 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11472 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11473 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11474 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11475 | "socks4://socks_proxy:1080", |
| 11476 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11477 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11478 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11479 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11480 | NetworkIsolationKey(), |
| 11481 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11482 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11483 | }, |
| 11484 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11485 | "socks5://socks_proxy:1080", |
| 11486 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11487 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11488 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11489 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11490 | NetworkIsolationKey(), |
| 11491 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11492 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11493 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11494 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11495 | // SSL Tests |
| 11496 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11497 | "socks4://socks_proxy:1080", |
| 11498 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11499 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11500 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11501 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11502 | NetworkIsolationKey(), |
| 11503 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11504 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11505 | }, |
| 11506 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11507 | "socks5://socks_proxy:1080", |
| 11508 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11509 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11510 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11511 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11512 | NetworkIsolationKey(), |
| 11513 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11514 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11515 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11516 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11517 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11518 | "socks4://socks_proxy:1080", |
| 11519 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11520 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11521 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 11522 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11523 | NetworkIsolationKey(), |
| 11524 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11525 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11526 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11527 | }; |
| 11528 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11529 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11530 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11531 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11532 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11533 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11534 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11535 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11536 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11537 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11538 | ProxyServer proxy_server( |
| 11539 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11540 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11541 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11542 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11543 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11544 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11545 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11546 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11549 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11550 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11551 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11552 | EXPECT_EQ(tests[i].expected_group_id, |
| 11553 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11554 | } |
| 11555 | } |
| 11556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11557 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11558 | HttpRequestInfo request; |
| 11559 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11560 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11561 | request.traffic_annotation = |
| 11562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11563 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11564 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11565 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11566 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11567 | // This simulates failure resolving all hostnames; that means we will fail |
| 11568 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11569 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11570 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11572 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11574 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11578 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11580 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11581 | } |
| 11582 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11583 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11584 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11585 | HttpRequestInfo request; |
| 11586 | request.method = "GET"; |
| 11587 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11588 | request.traffic_annotation = |
| 11589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11590 | |
| 11591 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11592 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11593 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11594 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11595 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11598 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11604 | |
| 11605 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11606 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11607 | |
| 11608 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11609 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11610 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11611 | } |
| 11612 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11613 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11614 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11615 | HttpRequestInfo request; |
| 11616 | request.method = "GET"; |
| 11617 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11618 | request.traffic_annotation = |
| 11619 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11620 | |
| 11621 | MockRead data_reads[] = { |
| 11622 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11624 | }; |
| 11625 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11626 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11630 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11636 | |
| 11637 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11638 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11640 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11641 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11642 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11643 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11644 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11645 | |
| 11646 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11647 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11648 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11649 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11650 | |
| 11651 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11652 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11653 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11654 | } |
| 11655 | |
| 11656 | // Make sure that a dropped connection while draining the body for auth |
| 11657 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11658 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11659 | HttpRequestInfo request; |
| 11660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11661 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11662 | request.traffic_annotation = |
| 11663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11664 | |
| 11665 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11666 | MockWrite( |
| 11667 | "GET / HTTP/1.1\r\n" |
| 11668 | "Host: www.example.org\r\n" |
| 11669 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11670 | }; |
| 11671 | |
| 11672 | MockRead data_reads1[] = { |
| 11673 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11674 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11675 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11676 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11677 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11678 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11679 | }; |
| 11680 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11681 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11682 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11684 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11685 | // be issuing -- the final header line contains the credentials. |
| 11686 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11687 | MockWrite( |
| 11688 | "GET / HTTP/1.1\r\n" |
| 11689 | "Host: www.example.org\r\n" |
| 11690 | "Connection: keep-alive\r\n" |
| 11691 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11692 | }; |
| 11693 | |
| 11694 | // Lastly, the server responds with the actual content. |
| 11695 | MockRead data_reads2[] = { |
| 11696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11697 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11698 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11699 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11700 | }; |
| 11701 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11702 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11703 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11706 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11710 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11712 | |
| 11713 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11716 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11717 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11718 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11720 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11722 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11724 | |
| 11725 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11726 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11728 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11729 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11730 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11731 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11732 | } |
| 11733 | |
| 11734 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11735 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11736 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11737 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11738 | |
| 11739 | HttpRequestInfo request; |
| 11740 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11741 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11742 | request.traffic_annotation = |
| 11743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11744 | |
| 11745 | MockRead proxy_reads[] = { |
| 11746 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11747 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11748 | }; |
| 11749 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11750 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11751 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11752 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11753 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11756 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11757 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11758 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11761 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11763 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11765 | |
| 11766 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11767 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11768 | } |
| 11769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11770 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11771 | HttpRequestInfo request; |
| 11772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11773 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11774 | request.traffic_annotation = |
| 11775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11779 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11780 | MockRead data_reads[] = { |
| 11781 | 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] | 11782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11783 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11784 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11785 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11786 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11787 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11788 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11789 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11790 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11792 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11793 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11795 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11796 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11797 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11798 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11799 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11800 | |
| 11801 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11802 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11803 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11804 | } |
| 11805 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11806 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11807 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11808 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11809 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11810 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11811 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11813 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11814 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11815 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11816 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11817 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11818 | |
| 11819 | HttpRequestInfo request; |
| 11820 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11821 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11822 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11823 | request.traffic_annotation = |
| 11824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11825 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11828 | |
| 11829 | MockRead data_reads[] = { |
| 11830 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11831 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11832 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11833 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11834 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11837 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11841 | |
| 11842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11843 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11845 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11846 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11847 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11848 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11849 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11850 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11851 | } |
| 11852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11853 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11854 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11855 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11856 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11857 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11858 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11859 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11860 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11862 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11863 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11864 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11865 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11866 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11867 | |
| 11868 | HttpRequestInfo request; |
| 11869 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11870 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11871 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11872 | request.traffic_annotation = |
| 11873 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11874 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11875 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11878 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11879 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11882 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11886 | |
| 11887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11888 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11889 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11890 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11891 | } |
| 11892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11893 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11894 | class FakeUploadElementReader : public UploadElementReader { |
| 11895 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11896 | FakeUploadElementReader() = default; |
| 11897 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11898 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11899 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11900 | |
| 11901 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11902 | int Init(CompletionOnceCallback callback) override { |
| 11903 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11904 | return ERR_IO_PENDING; |
| 11905 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11906 | uint64_t GetContentLength() const override { return 0; } |
| 11907 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11908 | int Read(IOBuffer* buf, |
| 11909 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11910 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11911 | return ERR_FAILED; |
| 11912 | } |
| 11913 | |
| 11914 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11915 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11916 | }; |
| 11917 | |
| 11918 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11919 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11920 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11921 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11922 | |
| 11923 | HttpRequestInfo request; |
| 11924 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11925 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11926 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11927 | request.traffic_annotation = |
| 11928 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11929 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11930 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11931 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11932 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11933 | |
| 11934 | StaticSocketDataProvider data; |
| 11935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11936 | |
| 11937 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11938 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11940 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11941 | |
| 11942 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11943 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11944 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11945 | |
| 11946 | // Return Init()'s result after the transaction gets destroyed. |
| 11947 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11948 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11949 | } |
| 11950 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11951 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11952 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11953 | HttpRequestInfo request; |
| 11954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11955 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11956 | request.traffic_annotation = |
| 11957 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11958 | |
| 11959 | // First transaction will request a resource and receive a Basic challenge |
| 11960 | // with realm="first_realm". |
| 11961 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11962 | MockWrite( |
| 11963 | "GET / HTTP/1.1\r\n" |
| 11964 | "Host: www.example.org\r\n" |
| 11965 | "Connection: keep-alive\r\n" |
| 11966 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11967 | }; |
| 11968 | MockRead data_reads1[] = { |
| 11969 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11970 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11971 | "\r\n"), |
| 11972 | }; |
| 11973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11974 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11975 | // for first_realm. The server will reject and provide a challenge with |
| 11976 | // second_realm. |
| 11977 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11978 | MockWrite( |
| 11979 | "GET / HTTP/1.1\r\n" |
| 11980 | "Host: www.example.org\r\n" |
| 11981 | "Connection: keep-alive\r\n" |
| 11982 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11983 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11984 | }; |
| 11985 | MockRead data_reads2[] = { |
| 11986 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11987 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11988 | "\r\n"), |
| 11989 | }; |
| 11990 | |
| 11991 | // This again fails, and goes back to first_realm. Make sure that the |
| 11992 | // entry is removed from cache. |
| 11993 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11994 | MockWrite( |
| 11995 | "GET / HTTP/1.1\r\n" |
| 11996 | "Host: www.example.org\r\n" |
| 11997 | "Connection: keep-alive\r\n" |
| 11998 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11999 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12000 | }; |
| 12001 | MockRead data_reads3[] = { |
| 12002 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12003 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 12004 | "\r\n"), |
| 12005 | }; |
| 12006 | |
| 12007 | // Try one last time (with the correct password) and get the resource. |
| 12008 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12009 | MockWrite( |
| 12010 | "GET / HTTP/1.1\r\n" |
| 12011 | "Host: www.example.org\r\n" |
| 12012 | "Connection: keep-alive\r\n" |
| 12013 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 12014 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12015 | }; |
| 12016 | MockRead data_reads4[] = { |
| 12017 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12018 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12019 | "Content-Length: 5\r\n" |
| 12020 | "\r\n" |
| 12021 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12022 | }; |
| 12023 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12024 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 12025 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 12026 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 12027 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12028 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12029 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 12030 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 12031 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12033 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [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] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12037 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12038 | // Issue the first request with Authorize headers. There should be a |
| 12039 | // password prompt for first_realm waiting to be filled in after the |
| 12040 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12041 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12043 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12044 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12045 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12046 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12047 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12048 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12049 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12050 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12051 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12052 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12053 | |
| 12054 | // Issue the second request with an incorrect password. There should be a |
| 12055 | // password prompt for second_realm waiting to be filled in after the |
| 12056 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12057 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12058 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 12059 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12061 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12062 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12063 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12064 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12065 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12066 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12067 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12068 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12069 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12070 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12071 | |
| 12072 | // Issue the third request with another incorrect password. There should be |
| 12073 | // a password prompt for first_realm waiting to be filled in. If the password |
| 12074 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 12075 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12076 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12077 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 12078 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12080 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12081 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12082 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12083 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12084 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12085 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12086 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12087 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12088 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12089 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12090 | |
| 12091 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12092 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12093 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 12094 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12096 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12097 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12098 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12099 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12100 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12101 | } |
| 12102 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12103 | // Regression test for https://crbug.com/754395. |
| 12104 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12105 | MockRead data_reads[] = { |
| 12106 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12107 | MockRead(kAlternativeServiceHttpHeader), |
| 12108 | MockRead("\r\n"), |
| 12109 | MockRead("hello world"), |
| 12110 | MockRead(SYNCHRONOUS, OK), |
| 12111 | }; |
| 12112 | |
| 12113 | HttpRequestInfo request; |
| 12114 | request.method = "GET"; |
| 12115 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12116 | request.traffic_annotation = |
| 12117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12118 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12119 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12120 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12121 | |
| 12122 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12123 | ssl.ssl_info.cert = |
| 12124 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12125 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12126 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12128 | |
| 12129 | TestCompletionCallback callback; |
| 12130 | |
| 12131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12133 | |
| 12134 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12135 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12136 | |
| 12137 | url::SchemeHostPort test_server(request.url); |
| 12138 | HttpServerProperties* http_server_properties = |
| 12139 | session->http_server_properties(); |
| 12140 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12141 | http_server_properties |
| 12142 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12143 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12144 | |
| 12145 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12146 | |
| 12147 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12148 | ASSERT_TRUE(response); |
| 12149 | ASSERT_TRUE(response->headers); |
| 12150 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12151 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12152 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12153 | |
| 12154 | std::string response_data; |
| 12155 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12156 | EXPECT_EQ("hello world", response_data); |
| 12157 | |
| 12158 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12159 | http_server_properties |
| 12160 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12161 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12162 | } |
| 12163 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12164 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12165 | MockRead data_reads[] = { |
| 12166 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12167 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12168 | MockRead("\r\n"), |
| 12169 | MockRead("hello world"), |
| 12170 | MockRead(SYNCHRONOUS, OK), |
| 12171 | }; |
| 12172 | |
| 12173 | HttpRequestInfo request; |
| 12174 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12175 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12176 | request.traffic_annotation = |
| 12177 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12178 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12179 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12180 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12181 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12182 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12183 | ssl.ssl_info.cert = |
| 12184 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12185 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12187 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12188 | TestCompletionCallback callback; |
| 12189 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12190 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12191 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12192 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12193 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12195 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12196 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12197 | HttpServerProperties* http_server_properties = |
| 12198 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12199 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12200 | http_server_properties |
| 12201 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12202 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12203 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12204 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12206 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12207 | ASSERT_TRUE(response); |
| 12208 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12209 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12210 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12211 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12212 | |
| 12213 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12214 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12215 | EXPECT_EQ("hello world", response_data); |
| 12216 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12217 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12218 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12219 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12220 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12221 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12222 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12223 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12224 | } |
| 12225 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12226 | TEST_F(HttpNetworkTransactionTest, |
| 12227 | HonorAlternativeServiceHeaderWithNetworkIsolationKey) { |
| 12228 | base::test::ScopedFeatureList feature_list; |
| 12229 | feature_list.InitWithFeatures( |
| 12230 | // enabled_features |
| 12231 | {features::kPartitionHttpServerPropertiesByNetworkIsolationKey, |
| 12232 | // Need to partition connections by NetworkIsolationKey for |
| 12233 | // SpdySessionKeys to include NetworkIsolationKeys. |
| 12234 | features::kPartitionConnectionsByNetworkIsolationKey}, |
| 12235 | // disabled_features |
| 12236 | {}); |
| 12237 | // Since HttpServerProperties caches the feature value, have to create a new |
| 12238 | // one. |
| 12239 | session_deps_.http_server_properties = |
| 12240 | std::make_unique<HttpServerProperties>(); |
| 12241 | |
| 12242 | const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/")); |
| 12243 | const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 12244 | const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/")); |
| 12245 | const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
| 12246 | |
| 12247 | MockRead data_reads[] = { |
| 12248 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12249 | MockRead(kAlternativeServiceHttpHeader), |
| 12250 | MockRead("\r\n"), |
| 12251 | MockRead("hello world"), |
| 12252 | MockRead(SYNCHRONOUS, OK), |
| 12253 | }; |
| 12254 | |
| 12255 | HttpRequestInfo request; |
| 12256 | request.method = "GET"; |
| 12257 | request.url = GURL("https://www.example.org/"); |
| 12258 | request.traffic_annotation = |
| 12259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12260 | request.network_isolation_key = kNetworkIsolationKey1; |
| 12261 | |
| 12262 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 12263 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12264 | |
| 12265 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12266 | ssl.ssl_info.cert = |
| 12267 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12268 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12270 | |
| 12271 | TestCompletionCallback callback; |
| 12272 | |
| 12273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12275 | |
| 12276 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12278 | |
| 12279 | url::SchemeHostPort test_server(request.url); |
| 12280 | HttpServerProperties* http_server_properties = |
| 12281 | session->http_server_properties(); |
| 12282 | EXPECT_TRUE( |
| 12283 | http_server_properties |
| 12284 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey1) |
| 12285 | .empty()); |
| 12286 | |
| 12287 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12288 | |
| 12289 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12290 | ASSERT_TRUE(response); |
| 12291 | ASSERT_TRUE(response->headers); |
| 12292 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12293 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12294 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12295 | |
| 12296 | std::string response_data; |
| 12297 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12298 | EXPECT_EQ("hello world", response_data); |
| 12299 | |
| 12300 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12301 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12302 | kNetworkIsolationKey1); |
| 12303 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12304 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12305 | EXPECT_EQ(alternative_service, |
| 12306 | alternative_service_info_vector[0].alternative_service()); |
| 12307 | |
| 12308 | // Make sure the alternative service information is only associated with |
| 12309 | // kNetworkIsolationKey1. |
| 12310 | EXPECT_TRUE( |
| 12311 | http_server_properties |
| 12312 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12313 | .empty()); |
| 12314 | EXPECT_TRUE( |
| 12315 | http_server_properties |
| 12316 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey2) |
| 12317 | .empty()); |
| 12318 | } |
| 12319 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12320 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12321 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12322 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12323 | MockRead data_reads[] = { |
| 12324 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12325 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12326 | MockRead("\r\n"), |
| 12327 | MockRead("hello world"), |
| 12328 | MockRead(SYNCHRONOUS, OK), |
| 12329 | }; |
| 12330 | |
| 12331 | HttpRequestInfo request; |
| 12332 | request.method = "GET"; |
| 12333 | request.url = GURL("http://www.example.org/"); |
| 12334 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12335 | request.traffic_annotation = |
| 12336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12337 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12338 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12339 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12340 | |
| 12341 | TestCompletionCallback callback; |
| 12342 | |
| 12343 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12345 | |
| 12346 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12347 | HttpServerProperties* http_server_properties = |
| 12348 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12349 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12350 | http_server_properties |
| 12351 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12352 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12356 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12359 | ASSERT_TRUE(response); |
| 12360 | ASSERT_TRUE(response->headers); |
| 12361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12362 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12363 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12364 | |
| 12365 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12366 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12367 | EXPECT_EQ("hello world", response_data); |
| 12368 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12369 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12370 | http_server_properties |
| 12371 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12372 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12373 | } |
| 12374 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12375 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12376 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12377 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12378 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12379 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12380 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12381 | HttpRequestInfo request; |
| 12382 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12383 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12384 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12385 | request.traffic_annotation = |
| 12386 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12387 | |
| 12388 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12389 | StaticSocketDataProvider first_data; |
| 12390 | first_data.set_connect_data(mock_connect); |
| 12391 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12392 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12393 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12395 | |
| 12396 | MockRead data_reads[] = { |
| 12397 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12398 | MockRead(ASYNC, OK), |
| 12399 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12400 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12401 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12402 | |
| 12403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12404 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12405 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12406 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12407 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12408 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12409 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12410 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12411 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 12412 | alternative_service, expiration); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12415 | TestCompletionCallback callback; |
| 12416 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12417 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12418 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12419 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12420 | } |
| 12421 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12422 | // Regression test for https://crbug.com/615497: |
| 12423 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12424 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12425 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12426 | HttpRequestInfo request; |
| 12427 | request.method = "GET"; |
| 12428 | request.url = GURL("http://www.example.org/"); |
| 12429 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12430 | request.traffic_annotation = |
| 12431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12432 | |
| 12433 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12434 | StaticSocketDataProvider first_data; |
| 12435 | first_data.set_connect_data(mock_connect); |
| 12436 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12437 | |
| 12438 | MockRead data_reads[] = { |
| 12439 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12440 | MockRead(ASYNC, OK), |
| 12441 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12442 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12443 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12444 | |
| 12445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12446 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12447 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12448 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12449 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12450 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12451 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12452 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 12453 | alternative_service, expiration); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12455 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12456 | TestCompletionCallback callback; |
| 12457 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12458 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12459 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12460 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12461 | } |
| 12462 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12463 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12464 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12466 | HttpServerProperties* http_server_properties = |
| 12467 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12468 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12469 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12470 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12471 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12472 | test_server, NetworkIsolationKey(), alternative_service, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12473 | session->params().quic_params.supported_versions); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12474 | EXPECT_EQ(1u, |
| 12475 | http_server_properties |
| 12476 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12477 | .size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12478 | |
| 12479 | // Send a clear header. |
| 12480 | MockRead data_reads[] = { |
| 12481 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12482 | MockRead("Alt-Svc: clear\r\n"), |
| 12483 | MockRead("\r\n"), |
| 12484 | MockRead("hello world"), |
| 12485 | MockRead(SYNCHRONOUS, OK), |
| 12486 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12487 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12489 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12490 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12491 | ssl.ssl_info.cert = |
| 12492 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12493 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12495 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12496 | HttpRequestInfo request; |
| 12497 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12498 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12499 | request.traffic_annotation = |
| 12500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12501 | |
| 12502 | TestCompletionCallback callback; |
| 12503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12505 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12506 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12507 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12509 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12510 | ASSERT_TRUE(response); |
| 12511 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12512 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12513 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12514 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12515 | |
| 12516 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12517 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12518 | EXPECT_EQ("hello world", response_data); |
| 12519 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12520 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12521 | http_server_properties |
| 12522 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12523 | .empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12524 | } |
| 12525 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12526 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12527 | MockRead data_reads[] = { |
| 12528 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12529 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12530 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12531 | MockRead("hello world"), |
| 12532 | MockRead(SYNCHRONOUS, OK), |
| 12533 | }; |
| 12534 | |
| 12535 | HttpRequestInfo request; |
| 12536 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12537 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12538 | request.traffic_annotation = |
| 12539 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12540 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12541 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12543 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12544 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12545 | ssl.ssl_info.cert = |
| 12546 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12547 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12549 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12550 | TestCompletionCallback callback; |
| 12551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12557 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12558 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12559 | HttpServerProperties* http_server_properties = |
| 12560 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12561 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12562 | http_server_properties |
| 12563 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12564 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12565 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12566 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12568 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12569 | ASSERT_TRUE(response); |
| 12570 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12571 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12572 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12573 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12574 | |
| 12575 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12576 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12577 | EXPECT_EQ("hello world", response_data); |
| 12578 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12579 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12580 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12581 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12582 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12583 | |
| 12584 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12585 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12586 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12587 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12588 | 1234); |
| 12589 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12590 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12591 | } |
| 12592 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12593 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12594 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12595 | HostPortPair alternative("alternative.example.org", 443); |
| 12596 | std::string origin_url = "https://origin.example.org:443"; |
| 12597 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12598 | |
| 12599 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12600 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12601 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12603 | |
| 12604 | // HTTP/1.1 data for request. |
| 12605 | MockWrite http_writes[] = { |
| 12606 | MockWrite("GET / HTTP/1.1\r\n" |
| 12607 | "Host: alternative.example.org\r\n" |
| 12608 | "Connection: keep-alive\r\n\r\n"), |
| 12609 | }; |
| 12610 | |
| 12611 | MockRead http_reads[] = { |
| 12612 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12613 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12614 | "Content-Length: 40\r\n\r\n" |
| 12615 | "first HTTP/1.1 response from alternative"), |
| 12616 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12617 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12618 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12619 | |
| 12620 | StaticSocketDataProvider data_refused; |
| 12621 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12622 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12623 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12624 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12626 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12627 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12628 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12629 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12630 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12631 | server, NetworkIsolationKey(), alternative_service, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12632 | HttpNetworkSession::Params().quic_params.supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12633 | // Mark the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12634 | http_server_properties->MarkAlternativeServiceBroken(alternative_service, |
| 12635 | NetworkIsolationKey()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12636 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12637 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12639 | request.method = "GET"; |
| 12640 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12641 | request.traffic_annotation = |
| 12642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12643 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12644 | TestCompletionCallback callback; |
| 12645 | NetErrorDetails details; |
| 12646 | EXPECT_FALSE(details.quic_broken); |
| 12647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12648 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12649 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12650 | EXPECT_TRUE(details.quic_broken); |
| 12651 | } |
| 12652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12653 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12654 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12655 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12656 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12657 | std::string origin_url = "https://origin.example.org:443"; |
| 12658 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12659 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12660 | |
| 12661 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12662 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12663 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12665 | |
| 12666 | // HTTP/1.1 data for request. |
| 12667 | MockWrite http_writes[] = { |
| 12668 | MockWrite("GET / HTTP/1.1\r\n" |
| 12669 | "Host: alternative1.example.org\r\n" |
| 12670 | "Connection: keep-alive\r\n\r\n"), |
| 12671 | }; |
| 12672 | |
| 12673 | MockRead http_reads[] = { |
| 12674 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12675 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12676 | "Content-Length: 40\r\n\r\n" |
| 12677 | "first HTTP/1.1 response from alternative1"), |
| 12678 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12679 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12680 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12681 | |
| 12682 | StaticSocketDataProvider data_refused; |
| 12683 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12684 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12685 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12687 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12688 | session->http_server_properties(); |
| 12689 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12690 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12691 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12692 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12693 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12694 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12695 | alternative_service_info_vector.push_back( |
| 12696 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12697 | alternative_service1, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12698 | session->params().quic_params.supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12699 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12700 | alternative_service_info_vector.push_back( |
| 12701 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12702 | alternative_service2, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12703 | session->params().quic_params.supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12704 | |
| 12705 | http_server_properties->SetAlternativeServices( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12706 | server, NetworkIsolationKey(), alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12707 | |
| 12708 | // Mark one of the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12709 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1, |
| 12710 | NetworkIsolationKey()); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12711 | EXPECT_EQ(2u, http_server_properties |
| 12712 | ->GetAlternativeServiceInfos(server, NetworkIsolationKey()) |
| 12713 | .size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12714 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12715 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12717 | request.method = "GET"; |
| 12718 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12719 | request.traffic_annotation = |
| 12720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12721 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12722 | TestCompletionCallback callback; |
| 12723 | NetErrorDetails details; |
| 12724 | EXPECT_FALSE(details.quic_broken); |
| 12725 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12726 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12727 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12728 | EXPECT_FALSE(details.quic_broken); |
| 12729 | } |
| 12730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12731 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12732 | HttpRequestInfo request; |
| 12733 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12734 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12735 | request.traffic_annotation = |
| 12736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12737 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12738 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12739 | StaticSocketDataProvider first_data; |
| 12740 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12741 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12742 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12743 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12745 | |
| 12746 | MockRead data_reads[] = { |
| 12747 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12748 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12749 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12750 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12751 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12752 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12753 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12755 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12756 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12757 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12758 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12759 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12760 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12761 | // Port is ignored by MockConnect anyway. |
| 12762 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12763 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12764 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12765 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12766 | server, NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12769 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12773 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12774 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12775 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12776 | ASSERT_TRUE(response); |
| 12777 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12778 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12779 | |
| 12780 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12781 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12782 | EXPECT_EQ("hello world", response_data); |
| 12783 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12784 | const AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12785 | http_server_properties->GetAlternativeServiceInfos(server, |
| 12786 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12787 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12788 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12789 | alternative_service_info_vector[0].alternative_service()); |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12790 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 12791 | alternative_service, NetworkIsolationKey())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12792 | } |
| 12793 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12794 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12795 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12796 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12797 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12798 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12799 | HttpRequestInfo restricted_port_request; |
| 12800 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12801 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12802 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12803 | restricted_port_request.traffic_annotation = |
| 12804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12805 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12806 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12807 | StaticSocketDataProvider first_data; |
| 12808 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12809 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12810 | |
| 12811 | MockRead data_reads[] = { |
| 12812 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12813 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12814 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12815 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12816 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12817 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12818 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12819 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12820 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12821 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12823 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12824 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12825 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12826 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12827 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12828 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12829 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12830 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12831 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 12832 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12835 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12837 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12838 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12840 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12841 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12842 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12843 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12844 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12845 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12846 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12847 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12848 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12849 | |
| 12850 | HttpRequestInfo restricted_port_request; |
| 12851 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12852 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12853 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12854 | restricted_port_request.traffic_annotation = |
| 12855 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12856 | |
| 12857 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12858 | StaticSocketDataProvider first_data; |
| 12859 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12860 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12861 | |
| 12862 | MockRead data_reads[] = { |
| 12863 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12864 | MockRead("hello world"), |
| 12865 | MockRead(ASYNC, OK), |
| 12866 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12867 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12868 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12869 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12870 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12874 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12875 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12876 | session->http_server_properties(); |
| 12877 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12878 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12879 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12880 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12881 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12882 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 12883 | alternative_service, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12885 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12886 | TestCompletionCallback callback; |
| 12887 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12888 | EXPECT_EQ(ERR_IO_PENDING, |
| 12889 | trans.Start(&restricted_port_request, callback.callback(), |
| 12890 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12891 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12892 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12893 | } |
| 12894 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12895 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12896 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12897 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12898 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12899 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12900 | HttpRequestInfo restricted_port_request; |
| 12901 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12902 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12903 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12904 | restricted_port_request.traffic_annotation = |
| 12905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12906 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12907 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12908 | StaticSocketDataProvider first_data; |
| 12909 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12910 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12911 | |
| 12912 | MockRead data_reads[] = { |
| 12913 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12914 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12915 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12916 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12917 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12918 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12919 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12920 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12921 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12924 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12925 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12926 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12927 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12928 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12929 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12930 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12931 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12932 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 12933 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12936 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12937 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12938 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12939 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12941 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12942 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12943 | } |
| 12944 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12945 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12946 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12947 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12948 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12949 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12950 | HttpRequestInfo unrestricted_port_request; |
| 12951 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12952 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12953 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12954 | unrestricted_port_request.traffic_annotation = |
| 12955 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12956 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12957 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12958 | StaticSocketDataProvider first_data; |
| 12959 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12960 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12961 | |
| 12962 | MockRead data_reads[] = { |
| 12963 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12964 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12965 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12966 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12967 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12968 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12969 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12970 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12971 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12972 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12974 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12975 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12976 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12977 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12978 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12979 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12980 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12981 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12982 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 12983 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12986 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12988 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12989 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12991 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12992 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12993 | } |
| 12994 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12995 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12996 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12997 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12998 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12999 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13000 | HttpRequestInfo unrestricted_port_request; |
| 13001 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13002 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13003 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13004 | unrestricted_port_request.traffic_annotation = |
| 13005 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13006 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13007 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13008 | StaticSocketDataProvider first_data; |
| 13009 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13010 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13011 | |
| 13012 | MockRead data_reads[] = { |
| 13013 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13014 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13015 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13016 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13017 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13018 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13019 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13020 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13022 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13024 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13025 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13026 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 13027 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13028 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13029 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13030 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13031 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13032 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 13033 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13036 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13038 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13039 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13041 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13042 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13043 | } |
| 13044 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13045 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 13046 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 13047 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13048 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13049 | HttpRequestInfo request; |
| 13050 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13051 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13052 | request.traffic_annotation = |
| 13053 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13054 | |
| 13055 | // The alternate protocol request will error out before we attempt to connect, |
| 13056 | // so only the standard HTTP request will try to connect. |
| 13057 | MockRead data_reads[] = { |
| 13058 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13059 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13060 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13061 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13062 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13066 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13067 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13068 | session->http_server_properties(); |
| 13069 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13070 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13071 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13072 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13073 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13074 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13075 | alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13078 | TestCompletionCallback callback; |
| 13079 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13080 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13082 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13083 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13085 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13086 | ASSERT_TRUE(response); |
| 13087 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13088 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13089 | |
| 13090 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13091 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13092 | EXPECT_EQ("hello world", response_data); |
| 13093 | } |
| 13094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13095 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13096 | HttpRequestInfo request; |
| 13097 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13098 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13099 | request.traffic_annotation = |
| 13100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13101 | |
| 13102 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13103 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13104 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13105 | MockRead("\r\n"), |
| 13106 | MockRead("hello world"), |
| 13107 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13108 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13109 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13110 | StaticSocketDataProvider first_transaction(data_reads, |
| 13111 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13112 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13113 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13114 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13116 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13117 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13118 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13119 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13120 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13121 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13122 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13123 | spdy::SpdySerializedFrame resp( |
| 13124 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13125 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13126 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13127 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13128 | }; |
| 13129 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13130 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13131 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13132 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13133 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13134 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13135 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13136 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13137 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13138 | &hanging_non_alternate_protocol_socket); |
| 13139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13140 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13141 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13143 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13144 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13145 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13146 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13148 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13149 | |
| 13150 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13151 | ASSERT_TRUE(response); |
| 13152 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13153 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13154 | |
| 13155 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13156 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13157 | EXPECT_EQ("hello world", response_data); |
| 13158 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13159 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13161 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13162 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13164 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13165 | |
| 13166 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13167 | ASSERT_TRUE(response); |
| 13168 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13169 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13170 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13171 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13172 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13173 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13174 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13175 | } |
| 13176 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13177 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13178 | HttpRequestInfo request; |
| 13179 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13180 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13181 | request.traffic_annotation = |
| 13182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13183 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13184 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13185 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13186 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13187 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13188 | MockRead("\r\n"), |
| 13189 | MockRead("hello world"), |
| 13190 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13191 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13192 | }; |
| 13193 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13194 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13195 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13196 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13197 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13198 | ssl_http11.ssl_info.cert = |
| 13199 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13200 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 13202 | |
| 13203 | // Second transaction starts an alternative and a non-alternative Job. |
| 13204 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13205 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13206 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13207 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13208 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 13209 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13210 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13211 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 13212 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13213 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13214 | // Third transaction starts an alternative and a non-alternative job. |
| 13215 | // The non-alternative job hangs, but the alternative one succeeds. |
| 13216 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13217 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13218 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13219 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13220 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13221 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13222 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13223 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13224 | spdy::SpdySerializedFrame resp1( |
| 13225 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13226 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13227 | spdy::SpdySerializedFrame resp2( |
| 13228 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13229 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13230 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13231 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13232 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13233 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13234 | }; |
| 13235 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13236 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13237 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13238 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13239 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13240 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13241 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13242 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13243 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13244 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13246 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13247 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13249 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13251 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13252 | |
| 13253 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13254 | ASSERT_TRUE(response); |
| 13255 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13256 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13257 | |
| 13258 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13259 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13260 | EXPECT_EQ("hello world", response_data); |
| 13261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13262 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13263 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13264 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13266 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13267 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13268 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13269 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13271 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13272 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13273 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13274 | |
| 13275 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13276 | ASSERT_TRUE(response); |
| 13277 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13278 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13279 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13280 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13281 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13282 | EXPECT_EQ("hello!", response_data); |
| 13283 | |
| 13284 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13285 | ASSERT_TRUE(response); |
| 13286 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13287 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13288 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13289 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13290 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13291 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13292 | } |
| 13293 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13294 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13295 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13296 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13297 | HttpRequestInfo request; |
| 13298 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13299 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13300 | request.traffic_annotation = |
| 13301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13302 | |
| 13303 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13304 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13305 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13306 | MockRead("\r\n"), |
| 13307 | MockRead("hello world"), |
| 13308 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13309 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13310 | }; |
| 13311 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13312 | StaticSocketDataProvider first_transaction(data_reads, |
| 13313 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13314 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13315 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13316 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13317 | ssl.ssl_info.cert = |
| 13318 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13319 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13321 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13322 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13323 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13324 | hanging_alternate_protocol_socket.set_connect_data( |
| 13325 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13326 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13327 | &hanging_alternate_protocol_socket); |
| 13328 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13329 | // 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] | 13330 | StaticSocketDataProvider second_transaction(data_reads, |
| 13331 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13332 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13335 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13338 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13340 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13341 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13343 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13344 | |
| 13345 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13346 | ASSERT_TRUE(response); |
| 13347 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13348 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13349 | |
| 13350 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13351 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13352 | EXPECT_EQ("hello world", response_data); |
| 13353 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13354 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13355 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13357 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13359 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13360 | |
| 13361 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13362 | ASSERT_TRUE(response); |
| 13363 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13364 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13365 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13366 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13367 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13368 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13369 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13370 | } |
| 13371 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13372 | // Test that proxy is resolved using the origin url, |
| 13373 | // regardless of the alternative server. |
| 13374 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13375 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13376 | ProxyConfig proxy_config; |
| 13377 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13378 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13379 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13380 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13381 | |
| 13382 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13383 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13384 | &capturing_proxy_resolver); |
| 13385 | |
| 13386 | TestNetLog net_log; |
| 13387 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13388 | session_deps_.proxy_resolution_service = |
| 13389 | std::make_unique<ProxyResolutionService>( |
| 13390 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13391 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13392 | |
| 13393 | session_deps_.net_log = &net_log; |
| 13394 | |
| 13395 | // Configure alternative service with a hostname that is not bypassed by the |
| 13396 | // proxy. |
| 13397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13398 | HttpServerProperties* http_server_properties = |
| 13399 | session->http_server_properties(); |
| 13400 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13401 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13402 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13403 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13404 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13405 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13406 | |
| 13407 | // Non-alternative job should hang. |
| 13408 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13409 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13410 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13411 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13412 | &hanging_alternate_protocol_socket); |
| 13413 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13414 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13415 | |
| 13416 | HttpRequestInfo request; |
| 13417 | request.method = "GET"; |
| 13418 | request.url = GURL("https://www.example.org/"); |
| 13419 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13420 | request.traffic_annotation = |
| 13421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13422 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13423 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13424 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13425 | |
| 13426 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13427 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13428 | spdy::SpdySerializedFrame resp( |
| 13429 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13430 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13431 | MockRead spdy_reads[] = { |
| 13432 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13433 | }; |
| 13434 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13435 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13436 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13437 | |
| 13438 | TestCompletionCallback callback; |
| 13439 | |
| 13440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13443 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13444 | |
| 13445 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13446 | ASSERT_TRUE(response); |
| 13447 | ASSERT_TRUE(response->headers); |
| 13448 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13449 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13450 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13451 | |
| 13452 | std::string response_data; |
| 13453 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13454 | EXPECT_EQ("hello!", response_data); |
| 13455 | |
| 13456 | // Origin host bypasses proxy, no resolution should have happened. |
| 13457 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13458 | } |
| 13459 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13460 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13461 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13462 | proxy_config.set_auto_detect(true); |
| 13463 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13464 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13465 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13466 | session_deps_.proxy_resolution_service = |
| 13467 | std::make_unique<ProxyResolutionService>( |
| 13468 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13469 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13470 | std::make_unique<CapturingProxyResolverFactory>( |
| 13471 | &capturing_proxy_resolver), |
| 13472 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13473 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13474 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13475 | |
| 13476 | HttpRequestInfo request; |
| 13477 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13478 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13479 | request.traffic_annotation = |
| 13480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13481 | |
| 13482 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13483 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13484 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13485 | MockRead("\r\n"), |
| 13486 | MockRead("hello world"), |
| 13487 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13488 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13489 | }; |
| 13490 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13491 | StaticSocketDataProvider first_transaction(data_reads, |
| 13492 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13493 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13494 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13495 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13497 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13498 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13499 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13500 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13501 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13502 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13503 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13504 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13505 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13506 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13507 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13508 | }; |
| 13509 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13510 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13511 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13512 | spdy::SpdySerializedFrame resp( |
| 13513 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13514 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13515 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13516 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13517 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13518 | }; |
| 13519 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13520 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13521 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13522 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13523 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13524 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13525 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13526 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13527 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13528 | &hanging_non_alternate_protocol_socket); |
| 13529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13530 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13531 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13533 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13534 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13535 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13536 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13538 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13539 | |
| 13540 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13541 | ASSERT_TRUE(response); |
| 13542 | ASSERT_TRUE(response->headers); |
| 13543 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13544 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13545 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13546 | |
| 13547 | std::string response_data; |
| 13548 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13549 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13550 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13551 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13552 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13554 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13556 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13557 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13558 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13559 | ASSERT_TRUE(response); |
| 13560 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13562 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13563 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13564 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13565 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13566 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13567 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13568 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13569 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13570 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13571 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13572 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13573 | LoadTimingInfo load_timing_info; |
| 13574 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13575 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13576 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13577 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13578 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13579 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13580 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13581 | HttpRequestInfo request; |
| 13582 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13583 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13584 | request.traffic_annotation = |
| 13585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13586 | |
| 13587 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13588 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13589 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13590 | MockRead("\r\n"), |
| 13591 | MockRead("hello world"), |
| 13592 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13593 | }; |
| 13594 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13595 | StaticSocketDataProvider first_transaction(data_reads, |
| 13596 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13597 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13598 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13599 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13601 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13602 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13603 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13604 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13605 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13606 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13607 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13608 | spdy::SpdySerializedFrame resp( |
| 13609 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13610 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13611 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13612 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13613 | }; |
| 13614 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13615 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13616 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13617 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13618 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13621 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13622 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13623 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13625 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13627 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13628 | |
| 13629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13630 | ASSERT_TRUE(response); |
| 13631 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13632 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13633 | |
| 13634 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13635 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13636 | EXPECT_EQ("hello world", response_data); |
| 13637 | |
| 13638 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13639 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13640 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13641 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 13642 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 13643 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13644 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13645 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13646 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13647 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13648 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13650 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13652 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13653 | |
| 13654 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13655 | ASSERT_TRUE(response); |
| 13656 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13657 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13658 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13659 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13660 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13661 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13662 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13663 | } |
| 13664 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13665 | // GenerateAuthToken is a mighty big test. |
| 13666 | // It tests all permutation of GenerateAuthToken behavior: |
| 13667 | // - Synchronous and Asynchronous completion. |
| 13668 | // - OK or error on completion. |
| 13669 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13670 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13671 | // - Non-authenticating and authenticating backend. |
| 13672 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13673 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13674 | // problems generating an auth token for an authenticating proxy, we don't |
| 13675 | // need to test all permutations of the backend server). |
| 13676 | // |
| 13677 | // The test proceeds by going over each of the configuration cases, and |
| 13678 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13679 | // specifies both the configuration for the test as well as the expectations |
| 13680 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13681 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13682 | static const char kServer[] = "http://www.example.com"; |
| 13683 | static const char kSecureServer[] = "https://www.example.com"; |
| 13684 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13685 | |
| 13686 | enum AuthTiming { |
| 13687 | AUTH_NONE, |
| 13688 | AUTH_SYNC, |
| 13689 | AUTH_ASYNC, |
| 13690 | }; |
| 13691 | |
| 13692 | const MockWrite kGet( |
| 13693 | "GET / HTTP/1.1\r\n" |
| 13694 | "Host: www.example.com\r\n" |
| 13695 | "Connection: keep-alive\r\n\r\n"); |
| 13696 | const MockWrite kGetProxy( |
| 13697 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13698 | "Host: www.example.com\r\n" |
| 13699 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13700 | const MockWrite kGetAuth( |
| 13701 | "GET / HTTP/1.1\r\n" |
| 13702 | "Host: www.example.com\r\n" |
| 13703 | "Connection: keep-alive\r\n" |
| 13704 | "Authorization: auth_token\r\n\r\n"); |
| 13705 | const MockWrite kGetProxyAuth( |
| 13706 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13707 | "Host: www.example.com\r\n" |
| 13708 | "Proxy-Connection: keep-alive\r\n" |
| 13709 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13710 | const MockWrite kGetAuthThroughProxy( |
| 13711 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13712 | "Host: www.example.com\r\n" |
| 13713 | "Proxy-Connection: keep-alive\r\n" |
| 13714 | "Authorization: auth_token\r\n\r\n"); |
| 13715 | const MockWrite kGetAuthWithProxyAuth( |
| 13716 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13717 | "Host: www.example.com\r\n" |
| 13718 | "Proxy-Connection: keep-alive\r\n" |
| 13719 | "Proxy-Authorization: auth_token\r\n" |
| 13720 | "Authorization: auth_token\r\n\r\n"); |
| 13721 | const MockWrite kConnect( |
| 13722 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13723 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13724 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13725 | const MockWrite kConnectProxyAuth( |
| 13726 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13727 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13728 | "Proxy-Connection: keep-alive\r\n" |
| 13729 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13730 | |
| 13731 | const MockRead kSuccess( |
| 13732 | "HTTP/1.1 200 OK\r\n" |
| 13733 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13734 | "Content-Length: 3\r\n\r\n" |
| 13735 | "Yes"); |
| 13736 | const MockRead kFailure( |
| 13737 | "Should not be called."); |
| 13738 | const MockRead kServerChallenge( |
| 13739 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13740 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13741 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13742 | "Content-Length: 14\r\n\r\n" |
| 13743 | "Unauthorized\r\n"); |
| 13744 | const MockRead kProxyChallenge( |
| 13745 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13746 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13747 | "Proxy-Connection: close\r\n" |
| 13748 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13749 | "Content-Length: 14\r\n\r\n" |
| 13750 | "Unauthorized\r\n"); |
| 13751 | const MockRead kProxyConnected( |
| 13752 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13753 | |
| 13754 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13755 | // no constructors, but the C++ compiler on Windows warns about |
| 13756 | // unspecified data in compound literals. So, moved to using constructors, |
| 13757 | // and TestRound's created with the default constructor should not be used. |
| 13758 | struct TestRound { |
| 13759 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13760 | : expected_rv(ERR_UNEXPECTED), |
| 13761 | extra_write(nullptr), |
| 13762 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13763 | TestRound(const MockWrite& write_arg, |
| 13764 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13765 | int expected_rv_arg) |
| 13766 | : write(write_arg), |
| 13767 | read(read_arg), |
| 13768 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13769 | extra_write(nullptr), |
| 13770 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13771 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13772 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13773 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13774 | : write(write_arg), |
| 13775 | read(read_arg), |
| 13776 | expected_rv(expected_rv_arg), |
| 13777 | extra_write(extra_write_arg), |
| 13778 | extra_read(extra_read_arg) { |
| 13779 | } |
| 13780 | MockWrite write; |
| 13781 | MockRead read; |
| 13782 | int expected_rv; |
| 13783 | const MockWrite* extra_write; |
| 13784 | const MockRead* extra_read; |
| 13785 | }; |
| 13786 | |
| 13787 | static const int kNoSSL = 500; |
| 13788 | |
| 13789 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13790 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13791 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13792 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13793 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13794 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13795 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13796 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13797 | int num_auth_rounds; |
| 13798 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13799 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13800 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13801 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13802 | {__LINE__, |
| 13803 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13804 | AUTH_NONE, |
| 13805 | OK, |
| 13806 | kServer, |
| 13807 | AUTH_NONE, |
| 13808 | OK, |
| 13809 | 1, |
| 13810 | kNoSSL, |
| 13811 | {TestRound(kGet, kSuccess, OK)}}, |
| 13812 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13813 | {__LINE__, |
| 13814 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13815 | AUTH_NONE, |
| 13816 | OK, |
| 13817 | kServer, |
| 13818 | AUTH_SYNC, |
| 13819 | OK, |
| 13820 | 2, |
| 13821 | kNoSSL, |
| 13822 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13823 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13824 | {__LINE__, |
| 13825 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13826 | AUTH_NONE, |
| 13827 | OK, |
| 13828 | kServer, |
| 13829 | AUTH_SYNC, |
| 13830 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13831 | 3, |
| 13832 | kNoSSL, |
| 13833 | {TestRound(kGet, kServerChallenge, OK), |
| 13834 | TestRound(kGet, kServerChallenge, OK), |
| 13835 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13836 | {__LINE__, |
| 13837 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13838 | AUTH_NONE, |
| 13839 | OK, |
| 13840 | kServer, |
| 13841 | AUTH_SYNC, |
| 13842 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13843 | 2, |
| 13844 | kNoSSL, |
| 13845 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13846 | {__LINE__, |
| 13847 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13848 | AUTH_NONE, |
| 13849 | OK, |
| 13850 | kServer, |
| 13851 | AUTH_SYNC, |
| 13852 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13853 | 2, |
| 13854 | kNoSSL, |
| 13855 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13856 | {__LINE__, |
| 13857 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13858 | AUTH_SYNC, |
| 13859 | ERR_FAILED, |
| 13860 | kServer, |
| 13861 | AUTH_NONE, |
| 13862 | OK, |
| 13863 | 2, |
| 13864 | kNoSSL, |
| 13865 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13866 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13867 | {__LINE__, |
| 13868 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13869 | AUTH_ASYNC, |
| 13870 | ERR_FAILED, |
| 13871 | kServer, |
| 13872 | AUTH_NONE, |
| 13873 | OK, |
| 13874 | 2, |
| 13875 | kNoSSL, |
| 13876 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13877 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13878 | {__LINE__, |
| 13879 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13880 | AUTH_NONE, |
| 13881 | OK, |
| 13882 | kServer, |
| 13883 | AUTH_SYNC, |
| 13884 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13885 | 2, |
| 13886 | kNoSSL, |
| 13887 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13888 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13889 | {__LINE__, |
| 13890 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13891 | AUTH_NONE, |
| 13892 | OK, |
| 13893 | kServer, |
| 13894 | AUTH_ASYNC, |
| 13895 | ERR_FAILED, |
| 13896 | 2, |
| 13897 | kNoSSL, |
| 13898 | {TestRound(kGet, kServerChallenge, OK), |
| 13899 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13900 | {__LINE__, |
| 13901 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13902 | AUTH_NONE, |
| 13903 | OK, |
| 13904 | kServer, |
| 13905 | AUTH_ASYNC, |
| 13906 | OK, |
| 13907 | 2, |
| 13908 | kNoSSL, |
| 13909 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13910 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13911 | {__LINE__, |
| 13912 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13913 | AUTH_NONE, |
| 13914 | OK, |
| 13915 | kServer, |
| 13916 | AUTH_ASYNC, |
| 13917 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13918 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13919 | kNoSSL, |
| 13920 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13921 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13922 | TestRound(kGet, kServerChallenge, OK), |
| 13923 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13924 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13925 | {__LINE__, |
| 13926 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13927 | AUTH_NONE, |
| 13928 | OK, |
| 13929 | kServer, |
| 13930 | AUTH_NONE, |
| 13931 | OK, |
| 13932 | 1, |
| 13933 | kNoSSL, |
| 13934 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13935 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13936 | {__LINE__, |
| 13937 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13938 | AUTH_NONE, |
| 13939 | OK, |
| 13940 | kServer, |
| 13941 | AUTH_SYNC, |
| 13942 | OK, |
| 13943 | 2, |
| 13944 | kNoSSL, |
| 13945 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13946 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13947 | {__LINE__, |
| 13948 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13949 | AUTH_NONE, |
| 13950 | OK, |
| 13951 | kServer, |
| 13952 | AUTH_SYNC, |
| 13953 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13954 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13955 | kNoSSL, |
| 13956 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13957 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13958 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13959 | {__LINE__, |
| 13960 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13961 | AUTH_NONE, |
| 13962 | OK, |
| 13963 | kServer, |
| 13964 | AUTH_ASYNC, |
| 13965 | OK, |
| 13966 | 2, |
| 13967 | kNoSSL, |
| 13968 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13969 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13970 | {__LINE__, |
| 13971 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13972 | AUTH_NONE, |
| 13973 | OK, |
| 13974 | kServer, |
| 13975 | AUTH_ASYNC, |
| 13976 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13977 | 2, |
| 13978 | kNoSSL, |
| 13979 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13980 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13981 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13982 | {__LINE__, |
| 13983 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13984 | AUTH_SYNC, |
| 13985 | OK, |
| 13986 | kServer, |
| 13987 | AUTH_NONE, |
| 13988 | OK, |
| 13989 | 2, |
| 13990 | kNoSSL, |
| 13991 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13992 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13993 | {__LINE__, |
| 13994 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13995 | AUTH_SYNC, |
| 13996 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13997 | kServer, |
| 13998 | AUTH_NONE, |
| 13999 | OK, |
| 14000 | 2, |
| 14001 | kNoSSL, |
| 14002 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14003 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14004 | {__LINE__, |
| 14005 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14006 | AUTH_ASYNC, |
| 14007 | OK, |
| 14008 | kServer, |
| 14009 | AUTH_NONE, |
| 14010 | OK, |
| 14011 | 2, |
| 14012 | kNoSSL, |
| 14013 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14014 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14015 | {__LINE__, |
| 14016 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14017 | AUTH_ASYNC, |
| 14018 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14019 | kServer, |
| 14020 | AUTH_NONE, |
| 14021 | OK, |
| 14022 | 2, |
| 14023 | kNoSSL, |
| 14024 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14025 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14026 | {__LINE__, |
| 14027 | kProxy, |
| 14028 | AUTH_ASYNC, |
| 14029 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14030 | kServer, |
| 14031 | AUTH_NONE, |
| 14032 | OK, |
| 14033 | 3, |
| 14034 | kNoSSL, |
| 14035 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14036 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14037 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14038 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14039 | {__LINE__, |
| 14040 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14041 | AUTH_SYNC, |
| 14042 | OK, |
| 14043 | kServer, |
| 14044 | AUTH_SYNC, |
| 14045 | OK, |
| 14046 | 3, |
| 14047 | kNoSSL, |
| 14048 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14049 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14050 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14051 | {__LINE__, |
| 14052 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14053 | AUTH_SYNC, |
| 14054 | OK, |
| 14055 | kServer, |
| 14056 | AUTH_SYNC, |
| 14057 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14058 | 3, |
| 14059 | kNoSSL, |
| 14060 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14061 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14062 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14063 | {__LINE__, |
| 14064 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14065 | AUTH_ASYNC, |
| 14066 | OK, |
| 14067 | kServer, |
| 14068 | AUTH_SYNC, |
| 14069 | OK, |
| 14070 | 3, |
| 14071 | kNoSSL, |
| 14072 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14073 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14074 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14075 | {__LINE__, |
| 14076 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14077 | AUTH_ASYNC, |
| 14078 | OK, |
| 14079 | kServer, |
| 14080 | AUTH_SYNC, |
| 14081 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14082 | 3, |
| 14083 | kNoSSL, |
| 14084 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14085 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14086 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14087 | {__LINE__, |
| 14088 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14089 | AUTH_SYNC, |
| 14090 | OK, |
| 14091 | kServer, |
| 14092 | AUTH_ASYNC, |
| 14093 | OK, |
| 14094 | 3, |
| 14095 | kNoSSL, |
| 14096 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14097 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14098 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14099 | {__LINE__, |
| 14100 | kProxy, |
| 14101 | AUTH_SYNC, |
| 14102 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14103 | kServer, |
| 14104 | AUTH_ASYNC, |
| 14105 | OK, |
| 14106 | 4, |
| 14107 | kNoSSL, |
| 14108 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14109 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14110 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14111 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 14112 | {__LINE__, |
| 14113 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14114 | AUTH_SYNC, |
| 14115 | OK, |
| 14116 | kServer, |
| 14117 | AUTH_ASYNC, |
| 14118 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14119 | 3, |
| 14120 | kNoSSL, |
| 14121 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14122 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14123 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14124 | {__LINE__, |
| 14125 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14126 | AUTH_ASYNC, |
| 14127 | OK, |
| 14128 | kServer, |
| 14129 | AUTH_ASYNC, |
| 14130 | OK, |
| 14131 | 3, |
| 14132 | kNoSSL, |
| 14133 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14134 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14135 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14136 | {__LINE__, |
| 14137 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14138 | AUTH_ASYNC, |
| 14139 | OK, |
| 14140 | kServer, |
| 14141 | AUTH_ASYNC, |
| 14142 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14143 | 3, |
| 14144 | kNoSSL, |
| 14145 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14146 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14147 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14148 | {__LINE__, |
| 14149 | kProxy, |
| 14150 | AUTH_ASYNC, |
| 14151 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14152 | kServer, |
| 14153 | AUTH_ASYNC, |
| 14154 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14155 | 4, |
| 14156 | kNoSSL, |
| 14157 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14158 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14159 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14160 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14161 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14162 | {__LINE__, |
| 14163 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14164 | AUTH_NONE, |
| 14165 | OK, |
| 14166 | kSecureServer, |
| 14167 | AUTH_NONE, |
| 14168 | OK, |
| 14169 | 1, |
| 14170 | 0, |
| 14171 | {TestRound(kGet, kSuccess, OK)}}, |
| 14172 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14173 | {__LINE__, |
| 14174 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14175 | AUTH_NONE, |
| 14176 | OK, |
| 14177 | kSecureServer, |
| 14178 | AUTH_SYNC, |
| 14179 | OK, |
| 14180 | 2, |
| 14181 | 0, |
| 14182 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14183 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14184 | {__LINE__, |
| 14185 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14186 | AUTH_NONE, |
| 14187 | OK, |
| 14188 | kSecureServer, |
| 14189 | AUTH_SYNC, |
| 14190 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14191 | 2, |
| 14192 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14193 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14194 | {__LINE__, |
| 14195 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14196 | AUTH_NONE, |
| 14197 | OK, |
| 14198 | kSecureServer, |
| 14199 | AUTH_ASYNC, |
| 14200 | OK, |
| 14201 | 2, |
| 14202 | 0, |
| 14203 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14204 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14205 | {__LINE__, |
| 14206 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14207 | AUTH_NONE, |
| 14208 | OK, |
| 14209 | kSecureServer, |
| 14210 | AUTH_ASYNC, |
| 14211 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14212 | 2, |
| 14213 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14214 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14215 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14216 | {__LINE__, |
| 14217 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14218 | AUTH_NONE, |
| 14219 | OK, |
| 14220 | kSecureServer, |
| 14221 | AUTH_NONE, |
| 14222 | OK, |
| 14223 | 1, |
| 14224 | 0, |
| 14225 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14226 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14227 | {__LINE__, |
| 14228 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14229 | AUTH_NONE, |
| 14230 | OK, |
| 14231 | kSecureServer, |
| 14232 | AUTH_SYNC, |
| 14233 | OK, |
| 14234 | 2, |
| 14235 | 0, |
| 14236 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14237 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14238 | {__LINE__, |
| 14239 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14240 | AUTH_NONE, |
| 14241 | OK, |
| 14242 | kSecureServer, |
| 14243 | AUTH_SYNC, |
| 14244 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14245 | 2, |
| 14246 | 0, |
| 14247 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14248 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14249 | {__LINE__, |
| 14250 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14251 | AUTH_NONE, |
| 14252 | OK, |
| 14253 | kSecureServer, |
| 14254 | AUTH_ASYNC, |
| 14255 | OK, |
| 14256 | 2, |
| 14257 | 0, |
| 14258 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14259 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14260 | {__LINE__, |
| 14261 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14262 | AUTH_NONE, |
| 14263 | OK, |
| 14264 | kSecureServer, |
| 14265 | AUTH_ASYNC, |
| 14266 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14267 | 2, |
| 14268 | 0, |
| 14269 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14270 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14271 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14272 | {__LINE__, |
| 14273 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14274 | AUTH_SYNC, |
| 14275 | OK, |
| 14276 | kSecureServer, |
| 14277 | AUTH_NONE, |
| 14278 | OK, |
| 14279 | 2, |
| 14280 | 1, |
| 14281 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14282 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14283 | {__LINE__, |
| 14284 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14285 | AUTH_SYNC, |
| 14286 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14287 | kSecureServer, |
| 14288 | AUTH_NONE, |
| 14289 | OK, |
| 14290 | 2, |
| 14291 | kNoSSL, |
| 14292 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14293 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14294 | {__LINE__, |
| 14295 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14296 | AUTH_SYNC, |
| 14297 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14298 | kSecureServer, |
| 14299 | AUTH_NONE, |
| 14300 | OK, |
| 14301 | 2, |
| 14302 | kNoSSL, |
| 14303 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14304 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14305 | {__LINE__, |
| 14306 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14307 | AUTH_SYNC, |
| 14308 | ERR_UNEXPECTED, |
| 14309 | kSecureServer, |
| 14310 | AUTH_NONE, |
| 14311 | OK, |
| 14312 | 2, |
| 14313 | kNoSSL, |
| 14314 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14315 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14316 | {__LINE__, |
| 14317 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14318 | AUTH_ASYNC, |
| 14319 | OK, |
| 14320 | kSecureServer, |
| 14321 | AUTH_NONE, |
| 14322 | OK, |
| 14323 | 2, |
| 14324 | 1, |
| 14325 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14326 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14327 | {__LINE__, |
| 14328 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14329 | AUTH_ASYNC, |
| 14330 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14331 | kSecureServer, |
| 14332 | AUTH_NONE, |
| 14333 | OK, |
| 14334 | 2, |
| 14335 | kNoSSL, |
| 14336 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14337 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14338 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14339 | {__LINE__, |
| 14340 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14341 | AUTH_SYNC, |
| 14342 | OK, |
| 14343 | kSecureServer, |
| 14344 | AUTH_SYNC, |
| 14345 | OK, |
| 14346 | 3, |
| 14347 | 1, |
| 14348 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14349 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14350 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14351 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14352 | {__LINE__, |
| 14353 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14354 | AUTH_SYNC, |
| 14355 | OK, |
| 14356 | kSecureServer, |
| 14357 | AUTH_SYNC, |
| 14358 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14359 | 3, |
| 14360 | 1, |
| 14361 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14362 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14363 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14364 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14365 | {__LINE__, |
| 14366 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14367 | AUTH_ASYNC, |
| 14368 | OK, |
| 14369 | kSecureServer, |
| 14370 | AUTH_SYNC, |
| 14371 | OK, |
| 14372 | 3, |
| 14373 | 1, |
| 14374 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14375 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14376 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14377 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14378 | {__LINE__, |
| 14379 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14380 | AUTH_ASYNC, |
| 14381 | OK, |
| 14382 | kSecureServer, |
| 14383 | AUTH_SYNC, |
| 14384 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14385 | 3, |
| 14386 | 1, |
| 14387 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14388 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14389 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14390 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14391 | {__LINE__, |
| 14392 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14393 | AUTH_SYNC, |
| 14394 | OK, |
| 14395 | kSecureServer, |
| 14396 | AUTH_ASYNC, |
| 14397 | OK, |
| 14398 | 3, |
| 14399 | 1, |
| 14400 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14401 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14402 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14403 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14404 | {__LINE__, |
| 14405 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14406 | AUTH_SYNC, |
| 14407 | OK, |
| 14408 | kSecureServer, |
| 14409 | AUTH_ASYNC, |
| 14410 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14411 | 3, |
| 14412 | 1, |
| 14413 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14414 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14415 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14416 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14417 | {__LINE__, |
| 14418 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14419 | AUTH_ASYNC, |
| 14420 | OK, |
| 14421 | kSecureServer, |
| 14422 | AUTH_ASYNC, |
| 14423 | OK, |
| 14424 | 3, |
| 14425 | 1, |
| 14426 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14427 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14428 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14429 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14430 | {__LINE__, |
| 14431 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14432 | AUTH_ASYNC, |
| 14433 | OK, |
| 14434 | kSecureServer, |
| 14435 | AUTH_ASYNC, |
| 14436 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14437 | 3, |
| 14438 | 1, |
| 14439 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14440 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14441 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14442 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14443 | {__LINE__, |
| 14444 | kProxy, |
| 14445 | AUTH_ASYNC, |
| 14446 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14447 | kSecureServer, |
| 14448 | AUTH_ASYNC, |
| 14449 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14450 | 4, |
| 14451 | 2, |
| 14452 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14453 | TestRound(kConnect, kProxyChallenge, OK), |
| 14454 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14455 | &kServerChallenge), |
| 14456 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14457 | }; |
| 14458 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14459 | for (const auto& test_config : test_configs) { |
| 14460 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14461 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14462 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14463 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14464 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14465 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14466 | |
| 14467 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14468 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14469 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14470 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14471 | std::string auth_challenge = "Mock realm=proxy"; |
| 14472 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14473 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14474 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14475 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14476 | empty_ssl_info, origin, |
| 14477 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14478 | auth_handler->SetGenerateExpectation( |
| 14479 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14480 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14481 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14482 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14483 | } |
| 14484 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14485 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14486 | std::string auth_challenge = "Mock realm=server"; |
| 14487 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14488 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14489 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14490 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14491 | empty_ssl_info, origin, |
| 14492 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14493 | auth_handler->SetGenerateExpectation( |
| 14494 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14495 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14496 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14497 | |
| 14498 | // The second handler always succeeds. It should only be used where there |
| 14499 | // are multiple auth sessions for server auth in the same network |
| 14500 | // transaction using the same auth scheme. |
| 14501 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14502 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14503 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14504 | empty_ssl_info, origin, |
| 14505 | NetLogWithSource()); |
| 14506 | second_handler->SetGenerateExpectation(true, OK); |
| 14507 | auth_factory->AddMockHandler(second_handler.release(), |
| 14508 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14509 | } |
| 14510 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14511 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14512 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14513 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14514 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14515 | session_deps_.proxy_resolution_service = |
| 14516 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14517 | } |
| 14518 | |
| 14519 | HttpRequestInfo request; |
| 14520 | request.method = "GET"; |
| 14521 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14522 | request.traffic_annotation = |
| 14523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14526 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14527 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14528 | |
| 14529 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14530 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14531 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14532 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14533 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14534 | |
| 14535 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14536 | mock_reads.back().push_back(read_write_round.read); |
| 14537 | mock_writes.back().push_back(read_write_round.write); |
| 14538 | |
| 14539 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14540 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14541 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14542 | mock_reads.push_back(std::vector<MockRead>()); |
| 14543 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14544 | } |
| 14545 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14546 | if (read_write_round.extra_read) { |
| 14547 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14548 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14549 | if (read_write_round.extra_write) { |
| 14550 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14551 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14552 | |
| 14553 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14554 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14555 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14556 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14557 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14558 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14559 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14560 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14561 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14562 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14563 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14564 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14565 | } |
| 14566 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14567 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14568 | // they are as well. |
| 14569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14570 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14571 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14572 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14573 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14574 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14575 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14576 | int rv; |
| 14577 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14578 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14579 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14580 | rv = trans.RestartWithAuth( |
| 14581 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14582 | } |
| 14583 | if (rv == ERR_IO_PENDING) |
| 14584 | rv = callback.WaitForResult(); |
| 14585 | |
| 14586 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14587 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14589 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14590 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14591 | continue; |
| 14592 | } |
| 14593 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14594 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14595 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14596 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14597 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14598 | } |
| 14599 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14600 | } |
| 14601 | } |
| 14602 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14603 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14604 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14605 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14606 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14607 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14608 | session_deps_.proxy_resolution_service = |
| 14609 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14610 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14611 | |
| 14612 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14613 | auth_handler->set_connection_based(true); |
| 14614 | std::string auth_challenge = "Mock realm=server"; |
| 14615 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14616 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14617 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14618 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14619 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14620 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14621 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14622 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14623 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14624 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14625 | HttpRequestInfo request; |
| 14626 | request.method = "GET"; |
| 14627 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14628 | request.traffic_annotation = |
| 14629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14632 | |
| 14633 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14634 | // to validate that the TCP socket is not released to the pool between |
| 14635 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14636 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14637 | CommonConnectJobParams common_connect_job_params( |
| 14638 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14639 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14640 | 50, // Max sockets for pool |
| 14641 | 1, // Max sockets per group |
| 14642 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 14643 | ProxyServer::Direct(), false, // is_for_websockets |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 14644 | &common_connect_job_params); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14645 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14646 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14647 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14648 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14651 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14652 | |
| 14653 | const MockWrite kGet( |
| 14654 | "GET / HTTP/1.1\r\n" |
| 14655 | "Host: www.example.com\r\n" |
| 14656 | "Connection: keep-alive\r\n\r\n"); |
| 14657 | const MockWrite kGetAuth( |
| 14658 | "GET / HTTP/1.1\r\n" |
| 14659 | "Host: www.example.com\r\n" |
| 14660 | "Connection: keep-alive\r\n" |
| 14661 | "Authorization: auth_token\r\n\r\n"); |
| 14662 | |
| 14663 | const MockRead kServerChallenge( |
| 14664 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14665 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14666 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14667 | "Content-Length: 14\r\n\r\n" |
| 14668 | "Unauthorized\r\n"); |
| 14669 | const MockRead kSuccess( |
| 14670 | "HTTP/1.1 200 OK\r\n" |
| 14671 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14672 | "Content-Length: 3\r\n\r\n" |
| 14673 | "Yes"); |
| 14674 | |
| 14675 | MockWrite writes[] = { |
| 14676 | // First round |
| 14677 | kGet, |
| 14678 | // Second round |
| 14679 | kGetAuth, |
| 14680 | // Third round |
| 14681 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14682 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14683 | kGetAuth, |
| 14684 | // Competing request |
| 14685 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14686 | }; |
| 14687 | MockRead reads[] = { |
| 14688 | // First round |
| 14689 | kServerChallenge, |
| 14690 | // Second round |
| 14691 | kServerChallenge, |
| 14692 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14693 | kServerChallenge, |
| 14694 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14695 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14696 | // Competing response |
| 14697 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14698 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14699 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14700 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14701 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14702 | const ClientSocketPool::GroupId kSocketGroup( |
| 14703 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 14704 | PrivacyMode::PRIVACY_MODE_DISABLED, NetworkIsolationKey(), |
| 14705 | false /* disable_secure_dns */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14706 | |
| 14707 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14708 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14709 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14710 | if (rv == ERR_IO_PENDING) |
| 14711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14712 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14713 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14714 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14715 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14716 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14717 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14718 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14719 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14720 | // In between rounds, another request comes in for the same domain. |
| 14721 | // It should not be able to grab the TCP socket that trans has already |
| 14722 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14723 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14724 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14725 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14726 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14728 | // callback_compete.WaitForResult at this point would stall forever, |
| 14729 | // since the HttpNetworkTransaction does not release the request back to |
| 14730 | // the pool until after authentication completes. |
| 14731 | |
| 14732 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14733 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14734 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14735 | if (rv == ERR_IO_PENDING) |
| 14736 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14737 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14738 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14739 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14740 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14741 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14742 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14743 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14744 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14745 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14746 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14747 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14748 | if (rv == ERR_IO_PENDING) |
| 14749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14750 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14751 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14752 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14753 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14754 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14755 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14756 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14757 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14758 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14759 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14760 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14761 | if (rv == ERR_IO_PENDING) |
| 14762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14763 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14764 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14765 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14766 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14767 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14768 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14769 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14770 | // auth handler should transition to a DONE state in concert with the remote |
| 14771 | // server. But that's not something we can test here with a mock handler. |
| 14772 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14773 | auth_handler->state()); |
| 14774 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14775 | // Read the body since the fourth round was successful. This will also |
| 14776 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14777 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14778 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14779 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14780 | if (rv == ERR_IO_PENDING) |
| 14781 | rv = callback.WaitForResult(); |
| 14782 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14783 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14784 | EXPECT_EQ(0, rv); |
| 14785 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14786 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14787 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14788 | |
| 14789 | // The competing request can now finish. Wait for the headers and then |
| 14790 | // read the body. |
| 14791 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14792 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14793 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14794 | if (rv == ERR_IO_PENDING) |
| 14795 | rv = callback.WaitForResult(); |
| 14796 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14797 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14798 | EXPECT_EQ(0, rv); |
| 14799 | |
| 14800 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14801 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14802 | } |
| 14803 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14804 | // This tests the case that a request is issued via http instead of spdy after |
| 14805 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14806 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14807 | HttpRequestInfo request; |
| 14808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14809 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14810 | request.traffic_annotation = |
| 14811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14812 | |
| 14813 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14814 | MockWrite( |
| 14815 | "GET / HTTP/1.1\r\n" |
| 14816 | "Host: www.example.org\r\n" |
| 14817 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14818 | }; |
| 14819 | |
| 14820 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14821 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14822 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14823 | MockRead("\r\n"), |
| 14824 | MockRead("hello world"), |
| 14825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14826 | }; |
| 14827 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14828 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14829 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14830 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14833 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14836 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14837 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14840 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14841 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14842 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14844 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14846 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14847 | ASSERT_TRUE(response); |
| 14848 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14849 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14850 | |
| 14851 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14852 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14853 | EXPECT_EQ("hello world", response_data); |
| 14854 | |
| 14855 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14856 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14857 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14858 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14859 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14860 | // immediate server closing of the socket. |
| 14861 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14862 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14863 | HttpRequestInfo request; |
| 14864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14865 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14866 | request.traffic_annotation = |
| 14867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14868 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14869 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14870 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14872 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14873 | spdy::SpdySerializedFrame req( |
| 14874 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14875 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14876 | |
| 14877 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14878 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14879 | }; |
| 14880 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14881 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14882 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14884 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14887 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14888 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14889 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14891 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14892 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14893 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14894 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14895 | // it gets it. This is needed since the auth handler may get destroyed |
| 14896 | // before we get a chance to query it. |
| 14897 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14898 | public: |
| 14899 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14900 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14901 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14902 | |
| 14903 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14904 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14905 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14906 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14907 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14908 | *url_ = request->url; |
| 14909 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14910 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14911 | } |
| 14912 | |
| 14913 | private: |
| 14914 | GURL* url_; |
| 14915 | }; |
| 14916 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14917 | // Test that if we cancel the transaction as the connection is completing, that |
| 14918 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14919 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14920 | // Setup everything about the connection to complete synchronously, so that |
| 14921 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14922 | // for is the callback from the HttpStreamRequest. |
| 14923 | // Then cancel the transaction. |
| 14924 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14925 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14926 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14927 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14928 | MockRead(SYNCHRONOUS, "hello world"), |
| 14929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14930 | }; |
| 14931 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14932 | HttpRequestInfo request; |
| 14933 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14934 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14935 | request.traffic_annotation = |
| 14936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14939 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14940 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14941 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14942 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14943 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14944 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14945 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14946 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14947 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14948 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14949 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14951 | trans.reset(); // Cancel the transaction here. |
| 14952 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14953 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14954 | } |
| 14955 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14956 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14957 | // stream is drained properly and added back to the socket pool. The main |
| 14958 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14959 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14960 | // deleted. |
| 14961 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14962 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14963 | MockRead data_reads[] = { |
| 14964 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14965 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14966 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14967 | MockRead(ASYNC, "1"), |
| 14968 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14969 | // HttpNetworkTransaction has been deleted. |
| 14970 | MockRead(ASYNC, "2"), |
| 14971 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14972 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14973 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14974 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14977 | |
| 14978 | { |
| 14979 | HttpRequestInfo request; |
| 14980 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14981 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14982 | request.traffic_annotation = |
| 14983 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14984 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14986 | TestCompletionCallback callback; |
| 14987 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14988 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14990 | callback.WaitForResult(); |
| 14991 | |
| 14992 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14993 | ASSERT_TRUE(response); |
| 14994 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14995 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14996 | |
| 14997 | // The transaction and HttpRequestInfo are deleted. |
| 14998 | } |
| 14999 | |
| 15000 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15001 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15002 | |
| 15003 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15004 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15005 | } |
| 15006 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15007 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15008 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15009 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15010 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15011 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15012 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15013 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15014 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15015 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15016 | HttpRequestInfo request; |
| 15017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15018 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15019 | request.traffic_annotation = |
| 15020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15021 | |
| 15022 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15023 | MockWrite( |
| 15024 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 15025 | "Host: www.example.org\r\n" |
| 15026 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15027 | }; |
| 15028 | |
| 15029 | MockRead data_reads1[] = { |
| 15030 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15031 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15032 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15033 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15034 | }; |
| 15035 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15036 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15037 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15039 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15041 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15042 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15043 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15044 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15045 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15047 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15049 | |
| 15050 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15051 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15053 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15054 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15055 | |
| 15056 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15057 | EXPECT_EQ(200, response->headers->response_code()); |
| 15058 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15059 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15060 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15061 | HostPortPair::FromString("myproxy:70")), |
| 15062 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15063 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15064 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15065 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15066 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15067 | |
| 15068 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15069 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15070 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15071 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15072 | } |
| 15073 | |
| 15074 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15075 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15076 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15077 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15078 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15079 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15080 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15082 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15083 | HttpRequestInfo request; |
| 15084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15085 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15086 | request.traffic_annotation = |
| 15087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15088 | |
| 15089 | // Since we have proxy, should try to establish tunnel. |
| 15090 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15091 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15092 | "Host: www.example.org:443\r\n" |
| 15093 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15094 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15095 | MockWrite("GET / HTTP/1.1\r\n" |
| 15096 | "Host: www.example.org\r\n" |
| 15097 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15098 | }; |
| 15099 | |
| 15100 | MockRead data_reads1[] = { |
| 15101 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15102 | |
| 15103 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15104 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15105 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15106 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15107 | }; |
| 15108 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15109 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15110 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15111 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15114 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15117 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15118 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15119 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15120 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15122 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15124 | |
| 15125 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15126 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15127 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15128 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15129 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15130 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15131 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15132 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15133 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15134 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15136 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15137 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15138 | |
| 15139 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15140 | EXPECT_EQ(200, response->headers->response_code()); |
| 15141 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15142 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15143 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15144 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15145 | HostPortPair::FromString("myproxy:70")), |
| 15146 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15147 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15148 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15149 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15150 | |
| 15151 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15152 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15153 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15154 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15155 | } |
| 15156 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15157 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 15158 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15159 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15160 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15161 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15162 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15163 | BoundTestNetLog log; |
| 15164 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15166 | |
| 15167 | HttpRequestInfo request; |
| 15168 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15169 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15170 | request.traffic_annotation = |
| 15171 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15172 | |
| 15173 | // Since we have proxy, should try to establish tunnel. |
| 15174 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15175 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 15176 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15177 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15178 | |
| 15179 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15180 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15181 | "Connection: keep-alive\r\n\r\n"), |
| 15182 | }; |
| 15183 | |
| 15184 | MockRead data_reads1[] = { |
| 15185 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15186 | |
| 15187 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15188 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15189 | MockRead("Content-Length: 100\r\n\r\n"), |
| 15190 | MockRead(SYNCHRONOUS, OK), |
| 15191 | }; |
| 15192 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15193 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15195 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15197 | |
| 15198 | TestCompletionCallback callback1; |
| 15199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15200 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15202 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15204 | |
| 15205 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15206 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15207 | auto entries = log.GetEntries(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15208 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15209 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15210 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15211 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15212 | entries, pos, |
| 15213 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15214 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15215 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15216 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15217 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15218 | |
| 15219 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15220 | EXPECT_EQ(200, response->headers->response_code()); |
| 15221 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15222 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15223 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15224 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15225 | HostPortPair::FromString("myproxy:70")), |
| 15226 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15227 | |
| 15228 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15229 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15230 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15231 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15232 | } |
| 15233 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15234 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15235 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15236 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15237 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15238 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15239 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15240 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15242 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15243 | HttpRequestInfo request; |
| 15244 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15245 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15246 | request.traffic_annotation = |
| 15247 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15248 | |
| 15249 | // Since we have proxy, should try to establish tunnel. |
| 15250 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15251 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15252 | "Host: www.example.org:443\r\n" |
| 15253 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15254 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15255 | MockWrite("GET / HTTP/1.1\r\n" |
| 15256 | "Host: www.example.org\r\n" |
| 15257 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15258 | }; |
| 15259 | |
| 15260 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15261 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15262 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15263 | }; |
| 15264 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15265 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15266 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15267 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15270 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15274 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15276 | |
| 15277 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15278 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15279 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15280 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15281 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15282 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15283 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15284 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15285 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15286 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15287 | } |
| 15288 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15289 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15290 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15291 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15292 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15293 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15294 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15295 | spdy::SpdySerializedFrame resp( |
| 15296 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15297 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15298 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15299 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15300 | }; |
| 15301 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15302 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15303 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15304 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15305 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15306 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15307 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15308 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15310 | |
| 15311 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15312 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15313 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15314 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 15315 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 15316 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15317 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15318 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15319 | |
| 15320 | HttpRequestInfo request; |
| 15321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15322 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15323 | request.traffic_annotation = |
| 15324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15327 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15328 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15329 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15331 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15332 | } |
| 15333 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15334 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15335 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15336 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15337 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15338 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15339 | request_info.url = GURL("https://www.example.com/"); |
| 15340 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15341 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15342 | request_info.traffic_annotation = |
| 15343 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15344 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15345 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15346 | MockWrite data_writes[] = { |
| 15347 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15348 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15349 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15356 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15357 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15358 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15359 | rv = callback.WaitForResult(); |
| 15360 | ASSERT_EQ(error, rv); |
| 15361 | } |
| 15362 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15363 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15364 | // Just check a grab bag of cert errors. |
| 15365 | static const int kErrors[] = { |
| 15366 | ERR_CERT_COMMON_NAME_INVALID, |
| 15367 | ERR_CERT_AUTHORITY_INVALID, |
| 15368 | ERR_CERT_DATE_INVALID, |
| 15369 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15370 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15371 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15372 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15373 | } |
| 15374 | } |
| 15375 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15376 | // Ensure that a client certificate is removed from the SSL client auth |
| 15377 | // cache when: |
| 15378 | // 1) No proxy is involved. |
| 15379 | // 2) TLS False Start is disabled. |
| 15380 | // 3) The initial TLS handshake requests a client certificate. |
| 15381 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15382 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15383 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15384 | request_info.url = GURL("https://www.example.com/"); |
| 15385 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15386 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15387 | request_info.traffic_annotation = |
| 15388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15389 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 15390 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15391 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15392 | |
| 15393 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15394 | // CertificateRequest is received for the first time, the handshake will |
| 15395 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15396 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15397 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15399 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15400 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15401 | |
| 15402 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15403 | // False Start is not being used, the result of the SSL handshake will be |
| 15404 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15405 | // matches the result of a server sending a handshake_failure alert, |
| 15406 | // rather than a Finished message, because it requires a client |
| 15407 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15408 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15409 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15411 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15412 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15413 | |
| 15414 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15415 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15416 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15417 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15418 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15419 | // requiring a client certificate, this fallback handshake should also |
| 15420 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15421 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15422 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15423 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15424 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15425 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15426 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15427 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15428 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15429 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15430 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15431 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15432 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15433 | // requiring a client certificate, this fallback handshake should also |
| 15434 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15435 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15436 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15438 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15439 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15440 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15443 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15444 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15445 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15446 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15447 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15448 | |
| 15449 | // Complete the SSL handshake, which should abort due to requiring a |
| 15450 | // client certificate. |
| 15451 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15452 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15453 | |
| 15454 | // Indicate that no certificate should be supplied. From the perspective |
| 15455 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15456 | // certificate, so this is the same as supply a |
| 15457 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15458 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15459 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15460 | |
| 15461 | // Ensure the certificate was added to the client auth cache before |
| 15462 | // allowing the connection to continue restarting. |
| 15463 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15464 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15465 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15466 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15467 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15468 | |
| 15469 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15470 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15471 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15473 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15474 | |
| 15475 | // Ensure that the client certificate is removed from the cache on a |
| 15476 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15477 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15478 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15479 | } |
| 15480 | |
| 15481 | // Ensure that a client certificate is removed from the SSL client auth |
| 15482 | // cache when: |
| 15483 | // 1) No proxy is involved. |
| 15484 | // 2) TLS False Start is enabled. |
| 15485 | // 3) The initial TLS handshake requests a client certificate. |
| 15486 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15487 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15488 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15489 | request_info.url = GURL("https://www.example.com/"); |
| 15490 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15491 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15492 | request_info.traffic_annotation = |
| 15493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15494 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 15495 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15496 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15497 | |
| 15498 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15499 | // return successfully after reading up to the peer's Certificate message. |
| 15500 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15501 | // enqueue application data to be sent in the same packet as the |
| 15502 | // ChangeCipherSpec and Finished messages. |
| 15503 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15504 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15505 | // Finished messages. If there was an error negotiating with the peer, |
| 15506 | // such as due to the peer requiring a client certificate when none was |
| 15507 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15508 | // called. |
| 15509 | |
| 15510 | // Like the non-False Start case, when a client certificate is requested by |
| 15511 | // the peer, the handshake is aborted during the Connect() call. |
| 15512 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15513 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15514 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15516 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15517 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15518 | |
| 15519 | // When a client certificate is supplied, Connect() will not be aborted |
| 15520 | // when the peer requests the certificate. Instead, the handshake will |
| 15521 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15522 | // the socket. The handshake messages are not processed until Read() is |
| 15523 | // called, which then detects that the handshake was aborted, due to the |
| 15524 | // peer sending a handshake_failure because it requires a client |
| 15525 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15526 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15527 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15529 | MockRead data2_reads[] = { |
| 15530 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15531 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15532 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15533 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15534 | |
| 15535 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15536 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15537 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15538 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15539 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15541 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15542 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15543 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15544 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15545 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15546 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15547 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15549 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15550 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15551 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15552 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15553 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15554 | ssl_data5.cert_request_info = cert_request.get(); |
| 15555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15556 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15557 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15558 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15560 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15561 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15562 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15563 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15564 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15565 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15566 | |
| 15567 | // Complete the SSL handshake, which should abort due to requiring a |
| 15568 | // client certificate. |
| 15569 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15570 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15571 | |
| 15572 | // Indicate that no certificate should be supplied. From the perspective |
| 15573 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15574 | // certificate, so this is the same as supply a |
| 15575 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15576 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15577 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15578 | |
| 15579 | // Ensure the certificate was added to the client auth cache before |
| 15580 | // allowing the connection to continue restarting. |
| 15581 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15582 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15583 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15584 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15585 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15586 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15587 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15588 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15589 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15590 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15591 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15592 | |
| 15593 | // Ensure that the client certificate is removed from the cache on a |
| 15594 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15595 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15596 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15597 | } |
| 15598 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15599 | // Ensure that a client certificate is removed from the SSL client auth |
| 15600 | // cache when: |
| 15601 | // 1) An HTTPS proxy is involved. |
| 15602 | // 3) The HTTPS proxy requests a client certificate. |
| 15603 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15604 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15605 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15606 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15607 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15608 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15609 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15610 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15611 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15612 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15613 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15614 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 15615 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15616 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15617 | requests[0].url = GURL("https://www.example.com/"); |
| 15618 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15619 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15620 | requests[0].traffic_annotation = |
| 15621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15622 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15623 | // HTTPS requests are tunneled. |
| 15624 | MockWrite https_writes[] = { |
| 15625 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 15626 | "Host: www.example.com:443\r\n" |
| 15627 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15628 | }; |
| 15629 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15630 | requests[1].url = GURL("http://www.example.com/"); |
| 15631 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15632 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15633 | requests[1].traffic_annotation = |
| 15634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15635 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15636 | // HTTP requests are not. |
| 15637 | MockWrite http_writes[] = { |
| 15638 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 15639 | "Host: www.example.com\r\n" |
| 15640 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15641 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15642 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15643 | // When the server rejects the client certificate, it will close the |
| 15644 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 15645 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 15646 | for (bool reject_in_connect : {true, false}) { |
| 15647 | SCOPED_TRACE(reject_in_connect); |
| 15648 | // Client certificate errors are typically signaled with |
| 15649 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 15650 | // protocol error. |
| 15651 | for (Error reject_error : |
| 15652 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 15653 | SCOPED_TRACE(reject_error); |
| 15654 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 15655 | for (const HttpRequestInfo& request : requests) { |
| 15656 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15657 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15658 | session_deps_.socket_factory = |
| 15659 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15660 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15661 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15662 | // [ssl_]data[1-2]. [ssl_]data3 is not needed because we do not retry |
| 15663 | // for proxies. Rather than represending the endpoint |
| 15664 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15665 | // (proxy:70). |
| 15666 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 15667 | ssl_data1.cert_request_info = cert_request.get(); |
| 15668 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15669 | StaticSocketDataProvider data1; |
| 15670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15671 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15672 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 15673 | base::Optional<StaticSocketDataProvider> data2; |
| 15674 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 15675 | if (reject_in_connect) { |
| 15676 | ssl_data2.emplace(ASYNC, reject_error); |
| 15677 | // There are no reads or writes. |
| 15678 | data2.emplace(); |
| 15679 | } else { |
| 15680 | ssl_data2.emplace(ASYNC, OK); |
| 15681 | // We will get one Write() in before observing the error in Read(). |
| 15682 | if (request.url.SchemeIsCryptographic()) { |
| 15683 | data2.emplace(error_in_read, https_writes); |
| 15684 | } else { |
| 15685 | data2.emplace(error_in_read, http_writes); |
| 15686 | } |
| 15687 | } |
| 15688 | ssl_data2->cert_request_info = cert_request.get(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15689 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15690 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 15691 | &ssl_data2.value()); |
| 15692 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15693 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15694 | std::unique_ptr<HttpNetworkSession> session = |
| 15695 | CreateSession(&session_deps_); |
| 15696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15697 | |
| 15698 | // Begin the SSL handshake with the proxy. |
| 15699 | TestCompletionCallback callback; |
| 15700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 15701 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15702 | |
| 15703 | // Complete the SSL handshake, which should abort due to requiring a |
| 15704 | // client certificate. |
| 15705 | rv = callback.WaitForResult(); |
| 15706 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15707 | |
| 15708 | // Indicate that no certificate should be supplied. From the |
| 15709 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 15710 | // real certificate, so this is the same as supply a |
| 15711 | // legitimate-but-unacceptable certificate. |
| 15712 | rv = |
| 15713 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 15714 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15715 | |
| 15716 | // Ensure the certificate was added to the client auth cache before |
| 15717 | // allowing the connection to continue restarting. |
| 15718 | scoped_refptr<X509Certificate> client_cert; |
| 15719 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15720 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15721 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15722 | ASSERT_FALSE(client_cert); |
| 15723 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15724 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15725 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15726 | HostPortPair("www.example.com", 443), &client_cert, |
| 15727 | &client_private_key)); |
| 15728 | |
| 15729 | // Restart the handshake. This will consume ssl_data2. The result code |
| 15730 | // is checked against what ssl_data2 should return. |
| 15731 | rv = callback.WaitForResult(); |
| 15732 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 15733 | IsError(reject_error))); |
| 15734 | |
| 15735 | // Now that the new handshake has failed, ensure that the client |
| 15736 | // certificate was removed from the client auth cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15737 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15738 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15739 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15740 | HostPortPair("www.example.com", 443), &client_cert, |
| 15741 | &client_private_key)); |
| 15742 | } |
| 15743 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15744 | } |
| 15745 | } |
| 15746 | |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15747 | // Test that HttpNetworkTransaction correctly handles (mocked) certificate |
| 15748 | // requests during a TLS renegotiation. |
| 15749 | TEST_F(HttpNetworkTransactionTest, CertificateRequestInRenego) { |
| 15750 | HttpRequestInfo request_info; |
| 15751 | request_info.url = GURL("https://www.example.com/"); |
| 15752 | request_info.method = "GET"; |
| 15753 | request_info.load_flags = LOAD_NORMAL; |
| 15754 | request_info.traffic_annotation = |
| 15755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 15756 | |
| 15757 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 15758 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
| 15759 | |
| 15760 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 15761 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 15762 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 15763 | ASSERT_TRUE(identity); |
| 15764 | |
| 15765 | // The first connection's handshake succeeds, but we get |
| 15766 | // ERR_SSL_CLIENT_AUTH_CERT_NEEDED instead of an HTTP response. |
| 15767 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 15768 | ssl_data1.cert_request_info = cert_request.get(); |
| 15769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15770 | MockWrite data1_writes[] = { |
| 15771 | MockWrite("GET / HTTP/1.1\r\n" |
| 15772 | "Host: www.example.com\r\n" |
| 15773 | "Connection: keep-alive\r\n\r\n"), |
| 15774 | }; |
| 15775 | MockRead data1_reads[] = { |
| 15776 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED), |
| 15777 | }; |
| 15778 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 15779 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15780 | |
| 15781 | // After supplying with certificate, we restart the request from the top, |
| 15782 | // which succeeds this time. |
| 15783 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 15784 | ssl_data2.expected_send_client_cert = true; |
| 15785 | ssl_data2.expected_client_cert = identity->certificate(); |
| 15786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 15787 | MockWrite data2_writes[] = { |
| 15788 | MockWrite("GET / HTTP/1.1\r\n" |
| 15789 | "Host: www.example.com\r\n" |
| 15790 | "Connection: keep-alive\r\n\r\n"), |
| 15791 | }; |
| 15792 | MockRead data2_reads[] = { |
| 15793 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15794 | "Content-Length: 0\r\n\r\n"), |
| 15795 | }; |
| 15796 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 15797 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15798 | |
| 15799 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 15800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15801 | |
| 15802 | TestCompletionCallback callback; |
| 15803 | int rv = callback.GetResult( |
| 15804 | trans.Start(&request_info, callback.callback(), NetLogWithSource())); |
| 15805 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15806 | |
| 15807 | rv = trans.RestartWithCertificate(identity->certificate(), |
| 15808 | identity->ssl_private_key(), |
| 15809 | callback.callback()); |
| 15810 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15811 | |
| 15812 | // Ensure the certificate was added to the client auth cache |
| 15813 | // allowing the connection to continue restarting. |
| 15814 | scoped_refptr<X509Certificate> client_cert; |
| 15815 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15816 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15817 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15818 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15819 | |
| 15820 | // Complete the handshake. The request now succeeds. |
| 15821 | rv = callback.WaitForResult(); |
| 15822 | ASSERT_THAT(rv, IsError(OK)); |
| 15823 | EXPECT_EQ(200, trans.GetResponseInfo()->headers->response_code()); |
| 15824 | |
| 15825 | // The client certificate remains in the cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15826 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15827 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15828 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15829 | } |
| 15830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15831 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15832 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15833 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15835 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15836 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15837 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15838 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15839 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15840 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15841 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15842 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15843 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15844 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15845 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15846 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15847 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15848 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15849 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15850 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15851 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15852 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15853 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15854 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15855 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15856 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15857 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15858 | }; |
| 15859 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15860 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15861 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15862 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15863 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15864 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15865 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15866 | HttpRequestInfo request1; |
| 15867 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15868 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15869 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15870 | request1.traffic_annotation = |
| 15871 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15872 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15873 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15874 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15876 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15877 | |
| 15878 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15879 | ASSERT_TRUE(response); |
| 15880 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15881 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15882 | |
| 15883 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15884 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15885 | EXPECT_EQ("hello!", response_data); |
| 15886 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15887 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15888 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15889 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15890 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15891 | |
| 15892 | HttpRequestInfo request2; |
| 15893 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15894 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15895 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15896 | request2.traffic_annotation = |
| 15897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15898 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15900 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15902 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15903 | |
| 15904 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15905 | ASSERT_TRUE(response); |
| 15906 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15907 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15908 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15909 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15910 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15911 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15912 | } |
| 15913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15914 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15915 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15916 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15918 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15919 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15920 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15921 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15922 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15923 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15924 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15925 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15926 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15927 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15928 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15929 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15930 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15931 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15932 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15933 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15934 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15935 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15936 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15937 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15938 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15939 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15940 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15941 | }; |
| 15942 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15943 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15944 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15945 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15946 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15947 | |
| 15948 | TestCompletionCallback callback; |
| 15949 | HttpRequestInfo request1; |
| 15950 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15951 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15952 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15953 | request1.traffic_annotation = |
| 15954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15955 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15957 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15959 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15960 | |
| 15961 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15962 | ASSERT_TRUE(response); |
| 15963 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15964 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15965 | |
| 15966 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15967 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15968 | EXPECT_EQ("hello!", response_data); |
| 15969 | |
| 15970 | HttpRequestInfo request2; |
| 15971 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15972 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15973 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15974 | request2.traffic_annotation = |
| 15975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15976 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15977 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15978 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15980 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15981 | |
| 15982 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15983 | ASSERT_TRUE(response); |
| 15984 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15985 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15986 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15987 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15988 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15989 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15990 | } |
| 15991 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15992 | // Regression test for https://crbug.com/546991. |
| 15993 | // The server might not be able to serve an IP pooled request, and might send a |
| 15994 | // 421 Misdirected Request response status to indicate this. |
| 15995 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15996 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15997 | // Two hosts resolve to the same IP address. |
| 15998 | const std::string ip_addr = "1.2.3.4"; |
| 15999 | IPAddress ip; |
| 16000 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16001 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16002 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16003 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16004 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16005 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16006 | |
| 16007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16008 | |
| 16009 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16010 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16011 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16012 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16013 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16014 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16015 | spdy::SpdySerializedFrame rst( |
| 16016 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16017 | MockWrite writes1[] = { |
| 16018 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16019 | CreateMockWrite(rst, 6), |
| 16020 | }; |
| 16021 | |
| 16022 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16023 | spdy::SpdySerializedFrame resp1( |
| 16024 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16025 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16026 | spdy::SpdyHeaderBlock response_headers; |
| 16027 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16028 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16029 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 16030 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16031 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16032 | |
| 16033 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16034 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16035 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16036 | |
| 16037 | AddSSLSocketData(); |
| 16038 | |
| 16039 | // Retry the second request on a second connection. |
| 16040 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16041 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16042 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 16043 | MockWrite writes2[] = { |
| 16044 | CreateMockWrite(req3, 0), |
| 16045 | }; |
| 16046 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16047 | spdy::SpdySerializedFrame resp3( |
| 16048 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16049 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16050 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 16051 | MockRead(ASYNC, 0, 3)}; |
| 16052 | |
| 16053 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16054 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16055 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16056 | |
| 16057 | AddSSLSocketData(); |
| 16058 | |
| 16059 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16060 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 16061 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16062 | EXPECT_THAT(rv, IsOk()); |
| 16063 | |
| 16064 | HttpRequestInfo request1; |
| 16065 | request1.method = "GET"; |
| 16066 | request1.url = GURL("https://www.example.org/"); |
| 16067 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16068 | request1.traffic_annotation = |
| 16069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16070 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16071 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16072 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16073 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 16074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16075 | rv = callback.WaitForResult(); |
| 16076 | EXPECT_THAT(rv, IsOk()); |
| 16077 | |
| 16078 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 16079 | ASSERT_TRUE(response); |
| 16080 | ASSERT_TRUE(response->headers); |
| 16081 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16082 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16083 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16084 | std::string response_data; |
| 16085 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 16086 | EXPECT_EQ("hello!", response_data); |
| 16087 | |
| 16088 | HttpRequestInfo request2; |
| 16089 | request2.method = "GET"; |
| 16090 | request2.url = GURL("https://mail.example.org/"); |
| 16091 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16092 | request2.traffic_annotation = |
| 16093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16094 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16095 | |
| 16096 | BoundTestNetLog log; |
| 16097 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 16098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16099 | rv = callback.WaitForResult(); |
| 16100 | EXPECT_THAT(rv, IsOk()); |
| 16101 | |
| 16102 | response = trans2.GetResponseInfo(); |
| 16103 | ASSERT_TRUE(response); |
| 16104 | ASSERT_TRUE(response->headers); |
| 16105 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16106 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16107 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16108 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 16109 | EXPECT_EQ("hello!", response_data); |
| 16110 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16111 | auto entries = log.GetEntries(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16112 | ExpectLogContainsSomewhere( |
| 16113 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16114 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16115 | } |
| 16116 | |
| 16117 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 16118 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 16119 | // portions of the response. |
| 16120 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 16121 | // Two hosts resolve to the same IP address. |
| 16122 | const std::string ip_addr = "1.2.3.4"; |
| 16123 | IPAddress ip; |
| 16124 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16125 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16126 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16127 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16128 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16129 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16130 | |
| 16131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16132 | |
| 16133 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16134 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16135 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16136 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16137 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16138 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16139 | spdy::SpdySerializedFrame rst( |
| 16140 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16141 | MockWrite writes1[] = { |
| 16142 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16143 | CreateMockWrite(rst, 6), |
| 16144 | }; |
| 16145 | |
| 16146 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16147 | spdy::SpdySerializedFrame resp1( |
| 16148 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16149 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16150 | spdy::SpdyHeaderBlock response_headers; |
| 16151 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16152 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16153 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 16154 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16155 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16156 | |
| 16157 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16158 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16160 | |
| 16161 | AddSSLSocketData(); |
| 16162 | |
| 16163 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 16164 | // Retry again. |
| 16165 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16166 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16167 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 16168 | MockWrite writes2[] = { |
| 16169 | CreateMockWrite(req3, 0), |
| 16170 | }; |
| 16171 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16172 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16173 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16174 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16175 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 16176 | MockRead(ASYNC, 0, 3)}; |
| 16177 | |
| 16178 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16179 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16180 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16181 | |
| 16182 | AddSSLSocketData(); |
| 16183 | |
| 16184 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16185 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 16186 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16187 | EXPECT_THAT(rv, IsOk()); |
| 16188 | |
| 16189 | HttpRequestInfo request1; |
| 16190 | request1.method = "GET"; |
| 16191 | request1.url = GURL("https://www.example.org/"); |
| 16192 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16193 | request1.traffic_annotation = |
| 16194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16195 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16196 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16197 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16198 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 16199 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16200 | rv = callback.WaitForResult(); |
| 16201 | EXPECT_THAT(rv, IsOk()); |
| 16202 | |
| 16203 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 16204 | ASSERT_TRUE(response); |
| 16205 | ASSERT_TRUE(response->headers); |
| 16206 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16207 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16208 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16209 | std::string response_data; |
| 16210 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 16211 | EXPECT_EQ("hello!", response_data); |
| 16212 | |
| 16213 | HttpRequestInfo request2; |
| 16214 | request2.method = "GET"; |
| 16215 | request2.url = GURL("https://mail.example.org/"); |
| 16216 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16217 | request2.traffic_annotation = |
| 16218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16219 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16220 | |
| 16221 | BoundTestNetLog log; |
| 16222 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 16223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16224 | rv = callback.WaitForResult(); |
| 16225 | EXPECT_THAT(rv, IsOk()); |
| 16226 | |
| 16227 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 16228 | // caller. |
| 16229 | response = trans2.GetResponseInfo(); |
| 16230 | ASSERT_TRUE(response); |
| 16231 | ASSERT_TRUE(response->headers); |
| 16232 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 16233 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16234 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16235 | EXPECT_TRUE(response->ssl_info.cert); |
| 16236 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 16237 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16238 | } |
| 16239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16240 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 16241 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 16242 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 16243 | session_deps_.host_resolver = |
| 16244 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16246 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16247 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16248 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16249 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16250 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16251 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16252 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16253 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16254 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16255 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16256 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16257 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16258 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16259 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16260 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16261 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16262 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16263 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16264 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16265 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16266 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16267 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16268 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16269 | }; |
| 16270 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16271 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16272 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16273 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16274 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16275 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 16276 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16277 | HttpRequestInfo request1; |
| 16278 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16279 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16280 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16281 | request1.traffic_annotation = |
| 16282 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16283 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16285 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16287 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16288 | |
| 16289 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16290 | ASSERT_TRUE(response); |
| 16291 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16292 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16293 | |
| 16294 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16295 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16296 | EXPECT_EQ("hello!", response_data); |
| 16297 | |
| 16298 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16299 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 16300 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16302 | |
| 16303 | HttpRequestInfo request2; |
| 16304 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16305 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16306 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16307 | request2.traffic_annotation = |
| 16308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16309 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16310 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16311 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16313 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16314 | |
| 16315 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16316 | ASSERT_TRUE(response); |
| 16317 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16318 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16319 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16320 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16321 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16322 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16323 | } |
| 16324 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16325 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16326 | const std::string https_url = "https://www.example.org:8080/"; |
| 16327 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16328 | |
| 16329 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16330 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16331 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16332 | |
| 16333 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16334 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16335 | }; |
| 16336 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16337 | spdy::SpdySerializedFrame resp1( |
| 16338 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16339 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16340 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16341 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16342 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16343 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16344 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16345 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16346 | |
| 16347 | // HTTP GET for the HTTP URL |
| 16348 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16349 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16350 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16351 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16352 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16353 | }; |
| 16354 | |
| 16355 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16356 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16357 | MockRead(ASYNC, 2, "hello"), |
| 16358 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16359 | }; |
| 16360 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16361 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16362 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16363 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16364 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16366 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16367 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16368 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16370 | |
| 16371 | // Start the first transaction to set up the SpdySession |
| 16372 | HttpRequestInfo request1; |
| 16373 | request1.method = "GET"; |
| 16374 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16375 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16376 | request1.traffic_annotation = |
| 16377 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16378 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16379 | TestCompletionCallback callback1; |
| 16380 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16381 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16382 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16383 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16384 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16385 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16386 | |
| 16387 | // Now, start the HTTP request |
| 16388 | HttpRequestInfo request2; |
| 16389 | request2.method = "GET"; |
| 16390 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16391 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16392 | request2.traffic_annotation = |
| 16393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16394 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16395 | TestCompletionCallback callback2; |
| 16396 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16397 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16398 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16399 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16400 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16401 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16402 | } |
| 16403 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16404 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16405 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16406 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16407 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16408 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16409 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16410 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16411 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16412 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16413 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16414 | |
| 16415 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16416 | // negotiated. |
| 16417 | StaticSocketDataProvider data; |
| 16418 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16419 | |
| 16420 | // 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] | 16421 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16422 | // mocked. This way the request relies on the alternate Job. |
| 16423 | StaticSocketDataProvider data_refused; |
| 16424 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16425 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16426 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16427 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16429 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16430 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16431 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16432 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16433 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16434 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16435 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16436 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16438 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16439 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16440 | request.traffic_annotation = |
| 16441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16442 | TestCompletionCallback callback; |
| 16443 | |
| 16444 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16445 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16446 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16447 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16448 | } |
| 16449 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16450 | // 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] | 16451 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16452 | // succeeds, the request should succeed, even if the latter fails because |
| 16453 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16454 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16455 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16456 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16457 | |
| 16458 | // Negotiate HTTP/1.1 with alternative. |
| 16459 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16460 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16462 | |
| 16463 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16464 | // negotiated. |
| 16465 | StaticSocketDataProvider data; |
| 16466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16467 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16468 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16469 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16470 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16472 | |
| 16473 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16474 | MockWrite("GET / HTTP/1.1\r\n" |
| 16475 | "Host: www.example.org\r\n" |
| 16476 | "Connection: keep-alive\r\n\r\n"), |
| 16477 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16478 | "Host: www.example.org\r\n" |
| 16479 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16480 | }; |
| 16481 | |
| 16482 | MockRead http_reads[] = { |
| 16483 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16484 | MockRead("Content-Type: text/html\r\n"), |
| 16485 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16486 | MockRead("foobar"), |
| 16487 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16488 | MockRead("Content-Type: text/html\r\n"), |
| 16489 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16490 | MockRead("another"), |
| 16491 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16492 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16493 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16494 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16495 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16497 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16498 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16499 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16500 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16501 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16502 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16503 | |
| 16504 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16505 | HttpRequestInfo request1; |
| 16506 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16507 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16508 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16509 | request1.traffic_annotation = |
| 16510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16511 | TestCompletionCallback callback1; |
| 16512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16513 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16514 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16515 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16516 | |
| 16517 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16518 | ASSERT_TRUE(response1); |
| 16519 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16520 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16521 | |
| 16522 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16523 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16524 | EXPECT_EQ("foobar", response_data1); |
| 16525 | |
| 16526 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16527 | // for alternative service. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 16528 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 16529 | alternative_service, NetworkIsolationKey())); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16530 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16531 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16532 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16533 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16534 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16535 | HttpRequestInfo request2; |
| 16536 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16537 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16538 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16539 | request2.traffic_annotation = |
| 16540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16541 | TestCompletionCallback callback2; |
| 16542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16543 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16544 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16545 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16546 | |
| 16547 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16548 | ASSERT_TRUE(response2); |
| 16549 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16550 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16551 | |
| 16552 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16553 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16554 | EXPECT_EQ("another", response_data2); |
| 16555 | } |
| 16556 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16557 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16558 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16559 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16560 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16561 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16562 | HostPortPair alternative("alternative.example.org", 443); |
| 16563 | std::string origin_url = "https://origin.example.org:443"; |
| 16564 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16565 | |
| 16566 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16567 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16568 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16570 | |
| 16571 | // HTTP/1.1 data for |request1| and |request2|. |
| 16572 | MockWrite http_writes[] = { |
| 16573 | MockWrite( |
| 16574 | "GET / HTTP/1.1\r\n" |
| 16575 | "Host: alternative.example.org\r\n" |
| 16576 | "Connection: keep-alive\r\n\r\n"), |
| 16577 | MockWrite( |
| 16578 | "GET / HTTP/1.1\r\n" |
| 16579 | "Host: alternative.example.org\r\n" |
| 16580 | "Connection: keep-alive\r\n\r\n"), |
| 16581 | }; |
| 16582 | |
| 16583 | MockRead http_reads[] = { |
| 16584 | MockRead( |
| 16585 | "HTTP/1.1 200 OK\r\n" |
| 16586 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16587 | "Content-Length: 40\r\n\r\n" |
| 16588 | "first HTTP/1.1 response from alternative"), |
| 16589 | MockRead( |
| 16590 | "HTTP/1.1 200 OK\r\n" |
| 16591 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16592 | "Content-Length: 41\r\n\r\n" |
| 16593 | "second HTTP/1.1 response from alternative"), |
| 16594 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16595 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16596 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16597 | |
| 16598 | // This test documents that an alternate Job should not pool to an already |
| 16599 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16600 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16601 | StaticSocketDataProvider data_refused; |
| 16602 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16603 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16604 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16605 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16607 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16608 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16609 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16610 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16611 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16612 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16613 | |
| 16614 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16615 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16616 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16617 | request1.method = "GET"; |
| 16618 | request1.url = GURL(alternative_url); |
| 16619 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16620 | request1.traffic_annotation = |
| 16621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16622 | TestCompletionCallback callback1; |
| 16623 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16624 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16625 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16626 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16627 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16628 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16629 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16630 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16631 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16632 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16633 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16634 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16635 | |
| 16636 | // Request for origin.example.org, which has an alternative service. This |
| 16637 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16638 | // 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] | 16639 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16640 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16641 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16642 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16643 | request2.method = "GET"; |
| 16644 | request2.url = GURL(origin_url); |
| 16645 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16646 | request2.traffic_annotation = |
| 16647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16648 | TestCompletionCallback callback2; |
| 16649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16650 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16651 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16652 | |
| 16653 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16654 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16655 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16656 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16657 | request3.method = "GET"; |
| 16658 | request3.url = GURL(alternative_url); |
| 16659 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16660 | request3.traffic_annotation = |
| 16661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16662 | TestCompletionCallback callback3; |
| 16663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16664 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16665 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16666 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16667 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16668 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16669 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16670 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16671 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16672 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16673 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16674 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16675 | } |
| 16676 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16677 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16678 | const std::string https_url = "https://www.example.org:8080/"; |
| 16679 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16680 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16681 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16682 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16683 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16684 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16685 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16686 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16687 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16688 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16689 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16690 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16691 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16692 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16693 | |
| 16694 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16695 | spdy::SpdyHeaderBlock req2_block; |
| 16696 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16697 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16698 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16699 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16700 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16701 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16702 | |
| 16703 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16704 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16705 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16706 | }; |
| 16707 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16708 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16709 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16710 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16711 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16712 | spdy::SpdySerializedFrame body1( |
| 16713 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16714 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16715 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16716 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16717 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16718 | spdy::SpdySerializedFrame resp2( |
| 16719 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16720 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16721 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16722 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16723 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16724 | CreateMockRead(wrapped_resp1, 4), |
| 16725 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16726 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16727 | CreateMockRead(resp2, 8), |
| 16728 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16729 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16730 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16731 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16732 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16733 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16734 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16735 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16736 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16737 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16738 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16739 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16740 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16741 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16742 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16744 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16745 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16747 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16748 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16749 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16750 | |
| 16751 | // Start the first transaction to set up the SpdySession |
| 16752 | HttpRequestInfo request1; |
| 16753 | request1.method = "GET"; |
| 16754 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16755 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16756 | request1.traffic_annotation = |
| 16757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16758 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16759 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16760 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16761 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16762 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16763 | data1.RunUntilPaused(); |
| 16764 | base::RunLoop().RunUntilIdle(); |
| 16765 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16766 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16767 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16768 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16769 | LoadTimingInfo load_timing_info1; |
| 16770 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16771 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16772 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16773 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16774 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16775 | HttpRequestInfo request2; |
| 16776 | request2.method = "GET"; |
| 16777 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16778 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16779 | request2.traffic_annotation = |
| 16780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16781 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16782 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16783 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16784 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16785 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16786 | data1.RunUntilPaused(); |
| 16787 | base::RunLoop().RunUntilIdle(); |
| 16788 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16789 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16790 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16791 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16792 | |
| 16793 | LoadTimingInfo load_timing_info2; |
| 16794 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16795 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16796 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16797 | // HTTP requests over a SPDY session should have a different connection |
| 16798 | // socket_log_id than requests over a tunnel. |
| 16799 | 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] | 16800 | } |
| 16801 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16802 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16803 | // that we do not pool other origins that resolve to the same IP when |
| 16804 | // the certificate does not match the new origin. |
| 16805 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16806 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16807 | const std::string url1 = "http://www.example.org/"; |
| 16808 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16809 | const std::string ip_addr = "1.2.3.4"; |
| 16810 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16811 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16812 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16813 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16814 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16815 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16816 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16817 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16818 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16819 | |
| 16820 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16821 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16822 | }; |
| 16823 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16824 | spdy::SpdySerializedFrame resp1( |
| 16825 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16826 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16827 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16828 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16829 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16830 | }; |
| 16831 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16832 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16833 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16834 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16835 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16836 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16837 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16838 | |
| 16839 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16840 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16841 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16842 | |
| 16843 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16844 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16845 | }; |
| 16846 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16847 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16848 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16849 | spdy::SpdySerializedFrame body2( |
| 16850 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16851 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16852 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16854 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16855 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16856 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16857 | |
| 16858 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16859 | // all others direct. |
| 16860 | ProxyConfig proxy_config; |
| 16861 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16862 | session_deps_.proxy_resolution_service = |
| 16863 | std::make_unique<ProxyResolutionService>( |
| 16864 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16865 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16866 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16867 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16868 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16869 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16870 | // Load a valid cert. Note, that this does not need to |
| 16871 | // be valid for proxy because the MockSSLClientSocket does |
| 16872 | // not actually verify it. But SpdySession will use this |
| 16873 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16874 | ssl1.ssl_info.cert = |
| 16875 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16876 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16879 | |
| 16880 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16881 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16883 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16884 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16885 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16886 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16887 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16889 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16890 | |
| 16891 | // Start the first transaction to set up the SpdySession |
| 16892 | HttpRequestInfo request1; |
| 16893 | request1.method = "GET"; |
| 16894 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16895 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16896 | request1.traffic_annotation = |
| 16897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16898 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16899 | TestCompletionCallback callback1; |
| 16900 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16901 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16902 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16903 | data1.RunUntilPaused(); |
| 16904 | base::RunLoop().RunUntilIdle(); |
| 16905 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16906 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16907 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16908 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16909 | |
| 16910 | // Now, start the HTTP request |
| 16911 | HttpRequestInfo request2; |
| 16912 | request2.method = "GET"; |
| 16913 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16914 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16915 | request2.traffic_annotation = |
| 16916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16917 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16918 | TestCompletionCallback callback2; |
| 16919 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16920 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16921 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16922 | |
| 16923 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16924 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16925 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16926 | } |
| 16927 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16928 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16929 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16930 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16931 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16932 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16933 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16934 | |
| 16935 | MockRead reads1[] = { |
| 16936 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16937 | }; |
| 16938 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16939 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16940 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16941 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16942 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16943 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16944 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16945 | }; |
| 16946 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16947 | spdy::SpdySerializedFrame resp2( |
| 16948 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16949 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16950 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16951 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16952 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16953 | }; |
| 16954 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16955 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16956 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16957 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16958 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16959 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16960 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16961 | |
| 16962 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16963 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16964 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16965 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16966 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16967 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16968 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16969 | |
| 16970 | // Start the first transaction to set up the SpdySession and verify that |
| 16971 | // connection was closed. |
| 16972 | HttpRequestInfo request1; |
| 16973 | request1.method = "GET"; |
| 16974 | request1.url = GURL(https_url); |
| 16975 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16976 | request1.traffic_annotation = |
| 16977 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16978 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16979 | TestCompletionCallback callback1; |
| 16980 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16981 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16982 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16983 | |
| 16984 | // Now, start the second request and make sure it succeeds. |
| 16985 | HttpRequestInfo request2; |
| 16986 | request2.method = "GET"; |
| 16987 | request2.url = GURL(https_url); |
| 16988 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16989 | request2.traffic_annotation = |
| 16990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16991 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16992 | TestCompletionCallback callback2; |
| 16993 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16994 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16995 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16996 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16997 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16998 | } |
| 16999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17000 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17001 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17002 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17003 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17004 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17005 | |
| 17006 | // Use two different hosts with different IPs so they don't get pooled. |
| 17007 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 17008 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17010 | |
| 17011 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17012 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17013 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17014 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17017 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17018 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17019 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17020 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17021 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17022 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17023 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17024 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17025 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17026 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17027 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17028 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17029 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17030 | }; |
| 17031 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17032 | // Use a separate test instance for the separate SpdySession that will be |
| 17033 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17034 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17035 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17036 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17037 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17038 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17039 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17040 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17041 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17042 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17043 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17044 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17045 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17046 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17047 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17048 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17049 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17050 | }; |
| 17051 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17052 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17053 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17054 | |
| 17055 | MockWrite http_write[] = { |
| 17056 | MockWrite("GET / HTTP/1.1\r\n" |
| 17057 | "Host: www.a.com\r\n" |
| 17058 | "Connection: keep-alive\r\n\r\n"), |
| 17059 | }; |
| 17060 | |
| 17061 | MockRead http_read[] = { |
| 17062 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17063 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 17064 | MockRead("Content-Length: 6\r\n\r\n"), |
| 17065 | MockRead("hello!"), |
| 17066 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17067 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17068 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17069 | |
| 17070 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17071 | SpdySessionKey spdy_session_key_a( |
| 17072 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 17073 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17074 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17075 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17076 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17077 | |
| 17078 | TestCompletionCallback callback; |
| 17079 | HttpRequestInfo request1; |
| 17080 | request1.method = "GET"; |
| 17081 | request1.url = GURL("https://www.a.com/"); |
| 17082 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17083 | request1.traffic_annotation = |
| 17084 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17085 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17086 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17088 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17090 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17091 | |
| 17092 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17093 | ASSERT_TRUE(response); |
| 17094 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17095 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17096 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17097 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17098 | |
| 17099 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17100 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17101 | EXPECT_EQ("hello!", response_data); |
| 17102 | trans.reset(); |
| 17103 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17104 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17105 | |
| 17106 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17107 | SpdySessionKey spdy_session_key_b( |
| 17108 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 17109 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17110 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17111 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17112 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17113 | HttpRequestInfo request2; |
| 17114 | request2.method = "GET"; |
| 17115 | request2.url = GURL("https://www.b.com/"); |
| 17116 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17117 | request2.traffic_annotation = |
| 17118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17119 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17120 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17121 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17122 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17124 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17125 | |
| 17126 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17127 | ASSERT_TRUE(response); |
| 17128 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17129 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17130 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17131 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17132 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17133 | EXPECT_EQ("hello!", response_data); |
| 17134 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17135 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17136 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17137 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17138 | |
| 17139 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17140 | SpdySessionKey spdy_session_key_a1( |
| 17141 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame^] | 17142 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17143 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17144 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17145 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17146 | HttpRequestInfo request3; |
| 17147 | request3.method = "GET"; |
| 17148 | request3.url = GURL("http://www.a.com/"); |
| 17149 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17150 | request3.traffic_annotation = |
| 17151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17152 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17153 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17154 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17155 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17157 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17158 | |
| 17159 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17160 | ASSERT_TRUE(response); |
| 17161 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17162 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 17163 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17164 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17165 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17166 | EXPECT_EQ("hello!", response_data); |
| 17167 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17168 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17169 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17170 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17171 | } |
| 17172 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17173 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17174 | HttpRequestInfo request; |
| 17175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17176 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17177 | request.traffic_annotation = |
| 17178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17182 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17183 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17184 | StaticSocketDataProvider data; |
| 17185 | data.set_connect_data(mock_connect); |
| 17186 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17187 | |
| 17188 | TestCompletionCallback callback; |
| 17189 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17190 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17191 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17192 | |
| 17193 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17194 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17195 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17196 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17197 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17198 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17199 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17200 | |
| 17201 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17202 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17203 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17204 | } |
| 17205 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17206 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17207 | HttpRequestInfo request; |
| 17208 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17209 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17210 | request.traffic_annotation = |
| 17211 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17215 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17216 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17217 | StaticSocketDataProvider data; |
| 17218 | data.set_connect_data(mock_connect); |
| 17219 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17220 | |
| 17221 | TestCompletionCallback callback; |
| 17222 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17223 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17224 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17225 | |
| 17226 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17227 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17228 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17229 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17230 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17231 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17232 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17233 | |
| 17234 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17235 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17236 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17237 | } |
| 17238 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17239 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17240 | HttpRequestInfo request; |
| 17241 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17242 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17243 | request.traffic_annotation = |
| 17244 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17245 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17247 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17248 | |
| 17249 | MockWrite data_writes[] = { |
| 17250 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17251 | }; |
| 17252 | MockRead data_reads[] = { |
| 17253 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 17254 | }; |
| 17255 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17256 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17258 | |
| 17259 | TestCompletionCallback callback; |
| 17260 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17261 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17263 | |
| 17264 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17265 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17266 | } |
| 17267 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17268 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17269 | HttpRequestInfo request; |
| 17270 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17271 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17272 | request.traffic_annotation = |
| 17273 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17274 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17276 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17277 | |
| 17278 | MockWrite data_writes[] = { |
| 17279 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 17280 | }; |
| 17281 | MockRead data_reads[] = { |
| 17282 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 17283 | }; |
| 17284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17285 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17287 | |
| 17288 | TestCompletionCallback callback; |
| 17289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17290 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17292 | |
| 17293 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17294 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17295 | } |
| 17296 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17297 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17298 | HttpRequestInfo request; |
| 17299 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17300 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17301 | request.traffic_annotation = |
| 17302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17303 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17306 | |
| 17307 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17308 | MockWrite( |
| 17309 | "GET / HTTP/1.1\r\n" |
| 17310 | "Host: www.example.org\r\n" |
| 17311 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17312 | }; |
| 17313 | MockRead data_reads[] = { |
| 17314 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17315 | }; |
| 17316 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17317 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17319 | |
| 17320 | TestCompletionCallback callback; |
| 17321 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17322 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17324 | |
| 17325 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17326 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17327 | } |
| 17328 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17329 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17330 | HttpRequestInfo request; |
| 17331 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17332 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17333 | request.traffic_annotation = |
| 17334 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17337 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17338 | |
| 17339 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17340 | MockWrite( |
| 17341 | "GET / HTTP/1.1\r\n" |
| 17342 | "Host: www.example.org\r\n" |
| 17343 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17344 | }; |
| 17345 | MockRead data_reads[] = { |
| 17346 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17347 | }; |
| 17348 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17349 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17351 | |
| 17352 | TestCompletionCallback callback; |
| 17353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17356 | |
| 17357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17358 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17359 | } |
| 17360 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17361 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17362 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17363 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17364 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17365 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17366 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17367 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17368 | |
| 17369 | // Set up SSL request. |
| 17370 | |
| 17371 | HttpRequestInfo ssl_request; |
| 17372 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17373 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17374 | ssl_request.traffic_annotation = |
| 17375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17376 | |
| 17377 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17378 | MockWrite( |
| 17379 | "GET / HTTP/1.1\r\n" |
| 17380 | "Host: www.example.org\r\n" |
| 17381 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17382 | }; |
| 17383 | MockRead ssl_reads[] = { |
| 17384 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17385 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17386 | MockRead("hello world"), |
| 17387 | MockRead(SYNCHRONOUS, OK), |
| 17388 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17389 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17390 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17391 | |
| 17392 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17394 | |
| 17395 | // Set up HTTP request. |
| 17396 | |
| 17397 | HttpRequestInfo http_request; |
| 17398 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17399 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17400 | http_request.traffic_annotation = |
| 17401 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17402 | |
| 17403 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17404 | MockWrite( |
| 17405 | "GET / HTTP/1.1\r\n" |
| 17406 | "Host: www.example.org\r\n" |
| 17407 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17408 | }; |
| 17409 | MockRead http_reads[] = { |
| 17410 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17411 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17412 | MockRead("falafel"), |
| 17413 | MockRead(SYNCHRONOUS, OK), |
| 17414 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17415 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17416 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17419 | |
| 17420 | // Start the SSL request. |
| 17421 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17422 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17423 | ASSERT_EQ(ERR_IO_PENDING, |
| 17424 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17425 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17426 | |
| 17427 | // Start the HTTP request. Pool should stall. |
| 17428 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17429 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17430 | ASSERT_EQ(ERR_IO_PENDING, |
| 17431 | http_trans.Start(&http_request, http_callback.callback(), |
| 17432 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17433 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17434 | |
| 17435 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17436 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17437 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17438 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17439 | EXPECT_EQ("hello world", response_data); |
| 17440 | |
| 17441 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17442 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17443 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17444 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17445 | |
| 17446 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17447 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17448 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17449 | EXPECT_EQ("falafel", response_data); |
| 17450 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17451 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17452 | } |
| 17453 | |
| 17454 | // Tests that when a SSL connection is established but there's no corresponding |
| 17455 | // request that needs it, the new socket is closed if the transport socket pool |
| 17456 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17457 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17458 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17459 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17460 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17461 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17462 | |
| 17463 | // Set up an ssl request. |
| 17464 | |
| 17465 | HttpRequestInfo ssl_request; |
| 17466 | ssl_request.method = "GET"; |
| 17467 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17468 | ssl_request.traffic_annotation = |
| 17469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17470 | |
| 17471 | // No data will be sent on the SSL socket. |
| 17472 | StaticSocketDataProvider ssl_data; |
| 17473 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17474 | |
| 17475 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17477 | |
| 17478 | // Set up HTTP request. |
| 17479 | |
| 17480 | HttpRequestInfo http_request; |
| 17481 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17482 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17483 | http_request.traffic_annotation = |
| 17484 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17485 | |
| 17486 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17487 | MockWrite( |
| 17488 | "GET / HTTP/1.1\r\n" |
| 17489 | "Host: www.example.org\r\n" |
| 17490 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17491 | }; |
| 17492 | MockRead http_reads[] = { |
| 17493 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17494 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17495 | MockRead("falafel"), |
| 17496 | MockRead(SYNCHRONOUS, OK), |
| 17497 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17498 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17499 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17500 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17502 | |
| 17503 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17504 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17505 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17506 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17507 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17508 | |
| 17509 | // Start the HTTP request. Pool should stall. |
| 17510 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17511 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17512 | ASSERT_EQ(ERR_IO_PENDING, |
| 17513 | http_trans.Start(&http_request, http_callback.callback(), |
| 17514 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17515 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17516 | |
| 17517 | // The SSL connection will automatically be closed once the connection is |
| 17518 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17519 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17520 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17521 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17522 | EXPECT_EQ("falafel", response_data); |
| 17523 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17524 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17525 | } |
| 17526 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17527 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17528 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17529 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17530 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17531 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17532 | |
| 17533 | HttpRequestInfo request; |
| 17534 | request.method = "POST"; |
| 17535 | request.url = GURL("http://www.foo.com/"); |
| 17536 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17537 | request.traffic_annotation = |
| 17538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17542 | // Send headers successfully, but get an error while sending the body. |
| 17543 | MockWrite data_writes[] = { |
| 17544 | MockWrite("POST / HTTP/1.1\r\n" |
| 17545 | "Host: www.foo.com\r\n" |
| 17546 | "Connection: keep-alive\r\n" |
| 17547 | "Content-Length: 3\r\n\r\n"), |
| 17548 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17549 | }; |
| 17550 | |
| 17551 | MockRead data_reads[] = { |
| 17552 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17553 | MockRead("hello world"), |
| 17554 | MockRead(SYNCHRONOUS, OK), |
| 17555 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17556 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17557 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17558 | |
| 17559 | TestCompletionCallback callback; |
| 17560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17561 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17563 | |
| 17564 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17565 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17567 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17568 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17569 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17570 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17571 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17572 | |
| 17573 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17574 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17575 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17576 | EXPECT_EQ("hello world", response_data); |
| 17577 | } |
| 17578 | |
| 17579 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17580 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17581 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17582 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17584 | MockWrite data_writes[] = { |
| 17585 | MockWrite("GET / HTTP/1.1\r\n" |
| 17586 | "Host: www.foo.com\r\n" |
| 17587 | "Connection: keep-alive\r\n\r\n"), |
| 17588 | MockWrite("POST / HTTP/1.1\r\n" |
| 17589 | "Host: www.foo.com\r\n" |
| 17590 | "Connection: keep-alive\r\n" |
| 17591 | "Content-Length: 3\r\n\r\n"), |
| 17592 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17593 | }; |
| 17594 | |
| 17595 | MockRead data_reads[] = { |
| 17596 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17597 | "Content-Length: 14\r\n\r\n"), |
| 17598 | MockRead("first response"), |
| 17599 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17600 | "Content-Length: 15\r\n\r\n"), |
| 17601 | MockRead("second response"), |
| 17602 | MockRead(SYNCHRONOUS, OK), |
| 17603 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17604 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17606 | |
| 17607 | TestCompletionCallback callback; |
| 17608 | HttpRequestInfo request1; |
| 17609 | request1.method = "GET"; |
| 17610 | request1.url = GURL("http://www.foo.com/"); |
| 17611 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17612 | request1.traffic_annotation = |
| 17613 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17614 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17615 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17616 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17617 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17619 | |
| 17620 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17622 | |
| 17623 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17624 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17625 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17626 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17627 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17628 | |
| 17629 | std::string response_data1; |
| 17630 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17632 | EXPECT_EQ("first response", response_data1); |
| 17633 | // Delete the transaction to release the socket back into the socket pool. |
| 17634 | trans1.reset(); |
| 17635 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17636 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17637 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17638 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17639 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17640 | |
| 17641 | HttpRequestInfo request2; |
| 17642 | request2.method = "POST"; |
| 17643 | request2.url = GURL("http://www.foo.com/"); |
| 17644 | request2.upload_data_stream = &upload_data_stream; |
| 17645 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17646 | request2.traffic_annotation = |
| 17647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17649 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17650 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17652 | |
| 17653 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17656 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17657 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17658 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17659 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17660 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17661 | |
| 17662 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17663 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17665 | EXPECT_EQ("second response", response_data2); |
| 17666 | } |
| 17667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17668 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17669 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17670 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17671 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17672 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17673 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17674 | |
| 17675 | HttpRequestInfo request; |
| 17676 | request.method = "POST"; |
| 17677 | request.url = GURL("http://www.foo.com/"); |
| 17678 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17679 | request.traffic_annotation = |
| 17680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17681 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17684 | // Send headers successfully, but get an error while sending the body. |
| 17685 | MockWrite data_writes[] = { |
| 17686 | MockWrite("POST / HTTP/1.1\r\n" |
| 17687 | "Host: www.foo.com\r\n" |
| 17688 | "Connection: keep-alive\r\n" |
| 17689 | "Content-Length: 3\r\n\r\n" |
| 17690 | "fo"), |
| 17691 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17692 | }; |
| 17693 | |
| 17694 | MockRead data_reads[] = { |
| 17695 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17696 | MockRead("hello world"), |
| 17697 | MockRead(SYNCHRONOUS, OK), |
| 17698 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17699 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17700 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17701 | |
| 17702 | TestCompletionCallback callback; |
| 17703 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17704 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17706 | |
| 17707 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17708 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17710 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17711 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17712 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17713 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17714 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17715 | |
| 17716 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17717 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17718 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17719 | EXPECT_EQ("hello world", response_data); |
| 17720 | } |
| 17721 | |
| 17722 | // This tests the more common case than the previous test, where headers and |
| 17723 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17724 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17725 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17726 | |
| 17727 | HttpRequestInfo request; |
| 17728 | request.method = "POST"; |
| 17729 | request.url = GURL("http://www.foo.com/"); |
| 17730 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17731 | request.traffic_annotation = |
| 17732 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17736 | // Send headers successfully, but get an error while sending the body. |
| 17737 | MockWrite data_writes[] = { |
| 17738 | MockWrite("POST / HTTP/1.1\r\n" |
| 17739 | "Host: www.foo.com\r\n" |
| 17740 | "Connection: keep-alive\r\n" |
| 17741 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17742 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17743 | }; |
| 17744 | |
| 17745 | MockRead data_reads[] = { |
| 17746 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17747 | MockRead("hello world"), |
| 17748 | MockRead(SYNCHRONOUS, OK), |
| 17749 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17750 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17752 | |
| 17753 | TestCompletionCallback callback; |
| 17754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17757 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17758 | // they can't be merged with the body in a single send. Not currently |
| 17759 | // necessary since a chunked body is never merged with headers, but this makes |
| 17760 | // the test more future proof. |
| 17761 | base::RunLoop().RunUntilIdle(); |
| 17762 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17763 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17764 | |
| 17765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17768 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17769 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17770 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17771 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17772 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17773 | |
| 17774 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17775 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17776 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17777 | EXPECT_EQ("hello world", response_data); |
| 17778 | } |
| 17779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17780 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17781 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17782 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17783 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17784 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17785 | |
| 17786 | HttpRequestInfo request; |
| 17787 | request.method = "POST"; |
| 17788 | request.url = GURL("http://www.foo.com/"); |
| 17789 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17790 | request.traffic_annotation = |
| 17791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17795 | |
| 17796 | MockWrite data_writes[] = { |
| 17797 | MockWrite("POST / HTTP/1.1\r\n" |
| 17798 | "Host: www.foo.com\r\n" |
| 17799 | "Connection: keep-alive\r\n" |
| 17800 | "Content-Length: 3\r\n\r\n"), |
| 17801 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17802 | }; |
| 17803 | |
| 17804 | MockRead data_reads[] = { |
| 17805 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17806 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17807 | MockRead("hello world"), |
| 17808 | MockRead(SYNCHRONOUS, OK), |
| 17809 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17810 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17811 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17812 | |
| 17813 | TestCompletionCallback callback; |
| 17814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17815 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17817 | |
| 17818 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17819 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17822 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17823 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17824 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17825 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17826 | |
| 17827 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17828 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17830 | EXPECT_EQ("hello world", response_data); |
| 17831 | } |
| 17832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17833 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17834 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17835 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17836 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17837 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17838 | |
| 17839 | HttpRequestInfo request; |
| 17840 | request.method = "POST"; |
| 17841 | request.url = GURL("http://www.foo.com/"); |
| 17842 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17843 | request.traffic_annotation = |
| 17844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17848 | // Send headers successfully, but get an error while sending the body. |
| 17849 | MockWrite data_writes[] = { |
| 17850 | MockWrite("POST / HTTP/1.1\r\n" |
| 17851 | "Host: www.foo.com\r\n" |
| 17852 | "Connection: keep-alive\r\n" |
| 17853 | "Content-Length: 3\r\n\r\n"), |
| 17854 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17855 | }; |
| 17856 | |
| 17857 | MockRead data_reads[] = { |
| 17858 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17859 | MockRead("hello world"), |
| 17860 | MockRead(SYNCHRONOUS, OK), |
| 17861 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17862 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17863 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17864 | |
| 17865 | TestCompletionCallback callback; |
| 17866 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17867 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17868 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17869 | |
| 17870 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17871 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17872 | } |
| 17873 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17874 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17875 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17876 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17877 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17878 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17879 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17880 | |
| 17881 | HttpRequestInfo request; |
| 17882 | request.method = "POST"; |
| 17883 | request.url = GURL("http://www.foo.com/"); |
| 17884 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17885 | request.traffic_annotation = |
| 17886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17890 | // Send headers successfully, but get an error while sending the body. |
| 17891 | MockWrite data_writes[] = { |
| 17892 | MockWrite("POST / HTTP/1.1\r\n" |
| 17893 | "Host: www.foo.com\r\n" |
| 17894 | "Connection: keep-alive\r\n" |
| 17895 | "Content-Length: 3\r\n\r\n"), |
| 17896 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17897 | }; |
| 17898 | |
| 17899 | MockRead data_reads[] = { |
| 17900 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17901 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17902 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17903 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17904 | MockRead(SYNCHRONOUS, OK), |
| 17905 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17906 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17908 | |
| 17909 | TestCompletionCallback callback; |
| 17910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17911 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17913 | |
| 17914 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17915 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17916 | } |
| 17917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17918 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17919 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17920 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17921 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17922 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17923 | |
| 17924 | HttpRequestInfo request; |
| 17925 | request.method = "POST"; |
| 17926 | request.url = GURL("http://www.foo.com/"); |
| 17927 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17928 | request.traffic_annotation = |
| 17929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17933 | // Send headers successfully, but get an error while sending the body. |
| 17934 | MockWrite data_writes[] = { |
| 17935 | MockWrite("POST / HTTP/1.1\r\n" |
| 17936 | "Host: www.foo.com\r\n" |
| 17937 | "Connection: keep-alive\r\n" |
| 17938 | "Content-Length: 3\r\n\r\n"), |
| 17939 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17940 | }; |
| 17941 | |
| 17942 | MockRead data_reads[] = { |
| 17943 | MockRead("HTTP 0.9 rocks!"), |
| 17944 | MockRead(SYNCHRONOUS, OK), |
| 17945 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17946 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17948 | |
| 17949 | TestCompletionCallback callback; |
| 17950 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17951 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17953 | |
| 17954 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17955 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17956 | } |
| 17957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17958 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17959 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17960 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17961 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17962 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17963 | |
| 17964 | HttpRequestInfo request; |
| 17965 | request.method = "POST"; |
| 17966 | request.url = GURL("http://www.foo.com/"); |
| 17967 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17968 | request.traffic_annotation = |
| 17969 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17970 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17973 | // Send headers successfully, but get an error while sending the body. |
| 17974 | MockWrite data_writes[] = { |
| 17975 | MockWrite("POST / HTTP/1.1\r\n" |
| 17976 | "Host: www.foo.com\r\n" |
| 17977 | "Connection: keep-alive\r\n" |
| 17978 | "Content-Length: 3\r\n\r\n"), |
| 17979 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17980 | }; |
| 17981 | |
| 17982 | MockRead data_reads[] = { |
| 17983 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17984 | MockRead(SYNCHRONOUS, OK), |
| 17985 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17986 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17988 | |
| 17989 | TestCompletionCallback callback; |
| 17990 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17991 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17993 | |
| 17994 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17995 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17996 | } |
| 17997 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17998 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17999 | |
| 18000 | namespace { |
| 18001 | |
| 18002 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 18003 | headers->SetHeader("Connection", "Upgrade"); |
| 18004 | headers->SetHeader("Upgrade", "websocket"); |
| 18005 | headers->SetHeader("Origin", "http://www.example.org"); |
| 18006 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18007 | } |
| 18008 | |
| 18009 | } // namespace |
| 18010 | |
| 18011 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18012 | for (bool secure : {true, false}) { |
| 18013 | MockWrite data_writes[] = { |
| 18014 | MockWrite("GET / HTTP/1.1\r\n" |
| 18015 | "Host: www.example.org\r\n" |
| 18016 | "Connection: Upgrade\r\n" |
| 18017 | "Upgrade: websocket\r\n" |
| 18018 | "Origin: http://www.example.org\r\n" |
| 18019 | "Sec-WebSocket-Version: 13\r\n" |
| 18020 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18021 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18022 | "client_max_window_bits\r\n\r\n")}; |
| 18023 | |
| 18024 | MockRead data_reads[] = { |
| 18025 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18026 | "Upgrade: websocket\r\n" |
| 18027 | "Connection: Upgrade\r\n" |
| 18028 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 18029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18030 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18032 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18033 | if (secure) |
| 18034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18035 | |
| 18036 | HttpRequestInfo request; |
| 18037 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18038 | request.url = |
| 18039 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18040 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18041 | request.traffic_annotation = |
| 18042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18043 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18044 | TestWebSocketHandshakeStreamCreateHelper |
| 18045 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18046 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18048 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18049 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18050 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18051 | |
| 18052 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18055 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18056 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 18057 | ASSERT_TRUE(stream_request); |
| 18058 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 18059 | stream_request->websocket_handshake_stream_create_helper()); |
| 18060 | |
| 18061 | rv = callback.WaitForResult(); |
| 18062 | EXPECT_THAT(rv, IsOk()); |
| 18063 | |
| 18064 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 18065 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18066 | } |
| 18067 | } |
| 18068 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18069 | // Verify that proxy headers are not sent to the destination server when |
| 18070 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18071 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18072 | HttpRequestInfo request; |
| 18073 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18074 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18075 | request.traffic_annotation = |
| 18076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18077 | AddWebSocketHeaders(&request.extra_headers); |
| 18078 | |
| 18079 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18080 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18081 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18082 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18085 | |
| 18086 | // Since a proxy is configured, try to establish a tunnel. |
| 18087 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18088 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18089 | "Host: www.example.org:443\r\n" |
| 18090 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18091 | |
| 18092 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18093 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18094 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18095 | "Host: www.example.org:443\r\n" |
| 18096 | "Proxy-Connection: keep-alive\r\n" |
| 18097 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18098 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18099 | MockWrite("GET / HTTP/1.1\r\n" |
| 18100 | "Host: www.example.org\r\n" |
| 18101 | "Connection: Upgrade\r\n" |
| 18102 | "Upgrade: websocket\r\n" |
| 18103 | "Origin: http://www.example.org\r\n" |
| 18104 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18105 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18106 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18107 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18108 | |
| 18109 | // The proxy responds to the connect with a 407, using a persistent |
| 18110 | // connection. |
| 18111 | MockRead data_reads[] = { |
| 18112 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18113 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 18114 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 18115 | "Content-Length: 0\r\n" |
| 18116 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18117 | |
| 18118 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18119 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18120 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18121 | "Upgrade: websocket\r\n" |
| 18122 | "Connection: Upgrade\r\n" |
| 18123 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18124 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18125 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18127 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18128 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18129 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18130 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18131 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18132 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18133 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18134 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18135 | &websocket_stream_create_helper); |
| 18136 | |
| 18137 | { |
| 18138 | TestCompletionCallback callback; |
| 18139 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18140 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18142 | |
| 18143 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18144 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18145 | } |
| 18146 | |
| 18147 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18148 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18149 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18150 | EXPECT_EQ(407, response->headers->response_code()); |
| 18151 | |
| 18152 | { |
| 18153 | TestCompletionCallback callback; |
| 18154 | |
| 18155 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 18156 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18158 | |
| 18159 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18160 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18161 | } |
| 18162 | |
| 18163 | response = trans->GetResponseInfo(); |
| 18164 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18165 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18166 | |
| 18167 | EXPECT_EQ(101, response->headers->response_code()); |
| 18168 | |
| 18169 | trans.reset(); |
| 18170 | session->CloseAllConnections(); |
| 18171 | } |
| 18172 | |
| 18173 | // Verify that proxy headers are not sent to the destination server when |
| 18174 | // establishing a tunnel for an insecure WebSocket connection. |
| 18175 | // This requires the authentication info to be injected into the auth cache |
| 18176 | // due to crbug.com/395064 |
| 18177 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18178 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18179 | HttpRequestInfo request; |
| 18180 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18181 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18182 | request.traffic_annotation = |
| 18183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18184 | AddWebSocketHeaders(&request.extra_headers); |
| 18185 | |
| 18186 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18187 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18188 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18189 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18190 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18192 | |
| 18193 | MockWrite data_writes[] = { |
| 18194 | // Try to establish a tunnel for the WebSocket connection, with |
| 18195 | // credentials. Because WebSockets have a separate set of socket pools, |
| 18196 | // they cannot and will not use the same TCP/IP connection as the |
| 18197 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18198 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 18199 | "Host: www.example.org:80\r\n" |
| 18200 | "Proxy-Connection: keep-alive\r\n" |
| 18201 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18202 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18203 | MockWrite("GET / HTTP/1.1\r\n" |
| 18204 | "Host: www.example.org\r\n" |
| 18205 | "Connection: Upgrade\r\n" |
| 18206 | "Upgrade: websocket\r\n" |
| 18207 | "Origin: http://www.example.org\r\n" |
| 18208 | "Sec-WebSocket-Version: 13\r\n" |
| 18209 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18210 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18211 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18212 | |
| 18213 | MockRead data_reads[] = { |
| 18214 | // HTTP CONNECT with credentials. |
| 18215 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18216 | |
| 18217 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18218 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18219 | "Upgrade: websocket\r\n" |
| 18220 | "Connection: Upgrade\r\n" |
| 18221 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18222 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18223 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18224 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18225 | |
| 18226 | session->http_auth_cache()->Add( |
| 18227 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 18228 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 18229 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18230 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18231 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18232 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18233 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18234 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18235 | &websocket_stream_create_helper); |
| 18236 | |
| 18237 | TestCompletionCallback callback; |
| 18238 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18239 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18241 | |
| 18242 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18243 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18244 | |
| 18245 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18246 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18247 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18248 | |
| 18249 | EXPECT_EQ(101, response->headers->response_code()); |
| 18250 | |
| 18251 | trans.reset(); |
| 18252 | session->CloseAllConnections(); |
| 18253 | } |
| 18254 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 18255 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 18256 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 18257 | for (bool secure : {true, false}) { |
| 18258 | SCOPED_TRACE(secure); |
| 18259 | session_deps_.proxy_resolution_service = |
| 18260 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18261 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18262 | session_deps_.enable_quic = true; |
| 18263 | |
| 18264 | HttpRequestInfo request; |
| 18265 | request.url = |
| 18266 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18267 | AddWebSocketHeaders(&request.extra_headers); |
| 18268 | request.traffic_annotation = |
| 18269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18270 | |
| 18271 | TestWebSocketHandshakeStreamCreateHelper |
| 18272 | websocket_handshake_stream_create_helper; |
| 18273 | |
| 18274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18275 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18276 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 18277 | &websocket_handshake_stream_create_helper); |
| 18278 | |
| 18279 | TestCompletionCallback callback; |
| 18280 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18282 | |
| 18283 | rv = callback.WaitForResult(); |
| 18284 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18285 | } |
| 18286 | } |
| 18287 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18288 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18289 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18290 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18291 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18292 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18293 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18294 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18295 | |
| 18296 | HttpRequestInfo request; |
| 18297 | request.method = "POST"; |
| 18298 | request.url = GURL("http://www.foo.com/"); |
| 18299 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18300 | request.traffic_annotation = |
| 18301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18305 | MockWrite data_writes[] = { |
| 18306 | MockWrite("POST / HTTP/1.1\r\n" |
| 18307 | "Host: www.foo.com\r\n" |
| 18308 | "Connection: keep-alive\r\n" |
| 18309 | "Content-Length: 3\r\n\r\n"), |
| 18310 | MockWrite("foo"), |
| 18311 | }; |
| 18312 | |
| 18313 | MockRead data_reads[] = { |
| 18314 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18315 | MockRead(SYNCHRONOUS, OK), |
| 18316 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18317 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18319 | |
| 18320 | TestCompletionCallback callback; |
| 18321 | |
| 18322 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18323 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18324 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18325 | |
| 18326 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18327 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18328 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18329 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18330 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18331 | } |
| 18332 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18333 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18334 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18335 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18336 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18337 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18338 | |
| 18339 | HttpRequestInfo request; |
| 18340 | request.method = "POST"; |
| 18341 | request.url = GURL("http://www.foo.com/"); |
| 18342 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18343 | request.traffic_annotation = |
| 18344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18345 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18346 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18347 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18348 | MockWrite data_writes[] = { |
| 18349 | MockWrite("POST / HTTP/1.1\r\n" |
| 18350 | "Host: www.foo.com\r\n" |
| 18351 | "Connection: keep-alive\r\n" |
| 18352 | "Content-Length: 3\r\n\r\n"), |
| 18353 | MockWrite("foo"), |
| 18354 | }; |
| 18355 | |
| 18356 | MockRead data_reads[] = { |
| 18357 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18358 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18359 | MockRead(SYNCHRONOUS, OK), |
| 18360 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18361 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18363 | |
| 18364 | TestCompletionCallback callback; |
| 18365 | |
| 18366 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18367 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18368 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18369 | |
| 18370 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18371 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18372 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18373 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18374 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18375 | } |
| 18376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18377 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18378 | ChunkedUploadDataStream upload_data_stream(0); |
| 18379 | |
| 18380 | HttpRequestInfo request; |
| 18381 | request.method = "POST"; |
| 18382 | request.url = GURL("http://www.foo.com/"); |
| 18383 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18384 | request.traffic_annotation = |
| 18385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18386 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18389 | // Send headers successfully, but get an error while sending the body. |
| 18390 | MockWrite data_writes[] = { |
| 18391 | MockWrite("POST / HTTP/1.1\r\n" |
| 18392 | "Host: www.foo.com\r\n" |
| 18393 | "Connection: keep-alive\r\n" |
| 18394 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18395 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18396 | }; |
| 18397 | |
| 18398 | MockRead data_reads[] = { |
| 18399 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18400 | MockRead(SYNCHRONOUS, OK), |
| 18401 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18402 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18404 | |
| 18405 | TestCompletionCallback callback; |
| 18406 | |
| 18407 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18408 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18409 | |
| 18410 | base::RunLoop().RunUntilIdle(); |
| 18411 | upload_data_stream.AppendData("f", 1, false); |
| 18412 | |
| 18413 | base::RunLoop().RunUntilIdle(); |
| 18414 | upload_data_stream.AppendData("oo", 2, true); |
| 18415 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18416 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18417 | |
| 18418 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18419 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18420 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18421 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18422 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18423 | } |
| 18424 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18425 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18426 | const std::string& accept_encoding, |
| 18427 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18428 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18429 | bool should_match) { |
| 18430 | HttpRequestInfo request; |
| 18431 | request.method = "GET"; |
| 18432 | request.url = GURL("http://www.foo.com/"); |
| 18433 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18434 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18435 | request.traffic_annotation = |
| 18436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18437 | |
| 18438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18439 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18440 | // Send headers successfully, but get an error while sending the body. |
| 18441 | MockWrite data_writes[] = { |
| 18442 | MockWrite("GET / HTTP/1.1\r\n" |
| 18443 | "Host: www.foo.com\r\n" |
| 18444 | "Connection: keep-alive\r\n" |
| 18445 | "Accept-Encoding: "), |
| 18446 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18447 | }; |
| 18448 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18449 | std::string response_code = "200 OK"; |
| 18450 | std::string extra; |
| 18451 | if (!location.empty()) { |
| 18452 | response_code = "301 Redirect\r\nLocation: "; |
| 18453 | response_code.append(location); |
| 18454 | } |
| 18455 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18456 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18457 | MockRead("HTTP/1.0 "), |
| 18458 | MockRead(response_code.data()), |
| 18459 | MockRead("\r\nContent-Encoding: "), |
| 18460 | MockRead(content_encoding.data()), |
| 18461 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18462 | MockRead(SYNCHRONOUS, OK), |
| 18463 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18464 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18465 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18466 | |
| 18467 | TestCompletionCallback callback; |
| 18468 | |
| 18469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18471 | |
| 18472 | rv = callback.WaitForResult(); |
| 18473 | if (should_match) { |
| 18474 | EXPECT_THAT(rv, IsOk()); |
| 18475 | } else { |
| 18476 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18477 | } |
| 18478 | } |
| 18479 | |
| 18480 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18481 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18482 | } |
| 18483 | |
| 18484 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18485 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18486 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18487 | } |
| 18488 | |
| 18489 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18490 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18491 | "", false); |
| 18492 | } |
| 18493 | |
| 18494 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18495 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18496 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18497 | } |
| 18498 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18499 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18500 | ProxyConfig proxy_config; |
| 18501 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18502 | proxy_config.set_pac_mandatory(true); |
| 18503 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18504 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18505 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18506 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18507 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18508 | |
| 18509 | HttpRequestInfo request; |
| 18510 | request.method = "GET"; |
| 18511 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18512 | request.traffic_annotation = |
| 18513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18514 | |
| 18515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18517 | |
| 18518 | TestCompletionCallback callback; |
| 18519 | |
| 18520 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18522 | EXPECT_THAT(callback.WaitForResult(), |
| 18523 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18524 | } |
| 18525 | |
| 18526 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18527 | ProxyConfig proxy_config; |
| 18528 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18529 | proxy_config.set_pac_mandatory(true); |
| 18530 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18531 | new MockAsyncProxyResolverFactory(false); |
| 18532 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18533 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18534 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18535 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18536 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18537 | HttpRequestInfo request; |
| 18538 | request.method = "GET"; |
| 18539 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18540 | request.traffic_annotation = |
| 18541 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18542 | |
| 18543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18545 | |
| 18546 | TestCompletionCallback callback; |
| 18547 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18549 | |
| 18550 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18551 | ERR_FAILED, &resolver); |
| 18552 | EXPECT_THAT(callback.WaitForResult(), |
| 18553 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18554 | } |
| 18555 | |
| 18556 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18557 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18558 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18559 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18560 | session_deps_.enable_quic = false; |
| 18561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18562 | |
| 18563 | HttpRequestInfo request; |
| 18564 | request.method = "GET"; |
| 18565 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18566 | request.traffic_annotation = |
| 18567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18568 | |
| 18569 | TestCompletionCallback callback; |
| 18570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18571 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18573 | |
| 18574 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18575 | } |
| 18576 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18577 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18578 | // Reporting tests |
| 18579 | |
| 18580 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18581 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18582 | protected: |
| 18583 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18584 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18585 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18586 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18587 | test_reporting_context_ = test_reporting_context.get(); |
| 18588 | session_deps_.reporting_service = |
| 18589 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18590 | } |
| 18591 | |
| 18592 | TestReportingContext* reporting_context() const { |
| 18593 | return test_reporting_context_; |
| 18594 | } |
| 18595 | |
| 18596 | void clear_reporting_service() { |
| 18597 | session_deps_.reporting_service.reset(); |
| 18598 | test_reporting_context_ = nullptr; |
| 18599 | } |
| 18600 | |
| 18601 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18602 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18603 | HttpRequestInfo request; |
| 18604 | request.method = "GET"; |
| 18605 | request.url = GURL(url_); |
| 18606 | request.traffic_annotation = |
| 18607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18608 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18609 | MockWrite data_writes[] = { |
| 18610 | MockWrite("GET / HTTP/1.1\r\n" |
| 18611 | "Host: www.example.org\r\n" |
| 18612 | "Connection: keep-alive\r\n\r\n"), |
| 18613 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18614 | MockRead data_reads[] = { |
| 18615 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18616 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18617 | "\"endpoints\": [{\"url\": " |
| 18618 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18619 | MockRead("\r\n"), |
| 18620 | MockRead("hello world"), |
| 18621 | MockRead(SYNCHRONOUS, OK), |
| 18622 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18623 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18624 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18625 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18626 | |
| 18627 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18628 | if (request.url.SchemeIsCryptographic()) { |
| 18629 | ssl.ssl_info.cert = |
| 18630 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18631 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18632 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18634 | } |
| 18635 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18636 | TestCompletionCallback callback; |
| 18637 | auto session = CreateSession(&session_deps_); |
| 18638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18640 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18641 | } |
| 18642 | |
| 18643 | protected: |
| 18644 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18645 | |
| 18646 | private: |
| 18647 | TestReportingContext* test_reporting_context_; |
| 18648 | }; |
| 18649 | |
| 18650 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18651 | DontProcessReportToHeaderNoService) { |
| 18652 | base::HistogramTester histograms; |
| 18653 | clear_reporting_service(); |
| 18654 | RequestPolicy(); |
| 18655 | histograms.ExpectBucketCount( |
| 18656 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18657 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18658 | } |
| 18659 | |
| 18660 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18661 | base::HistogramTester histograms; |
| 18662 | url_ = "http://www.example.org/"; |
| 18663 | RequestPolicy(); |
| 18664 | histograms.ExpectBucketCount( |
| 18665 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18666 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18667 | } |
| 18668 | |
| 18669 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18670 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18671 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 18672 | const ReportingEndpoint endpoint = |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18673 | reporting_context()->cache()->GetEndpointForTesting( |
| 18674 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18675 | GURL("https://www.example.org/upload/")); |
| 18676 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18677 | } |
| 18678 | |
| 18679 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18680 | DontProcessReportToHeaderInvalidHttps) { |
| 18681 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18682 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18683 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18684 | histograms.ExpectBucketCount( |
| 18685 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18686 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18687 | } |
| 18688 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18689 | |
| 18690 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18691 | // Network Error Logging tests |
| 18692 | |
| 18693 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18694 | namespace { |
| 18695 | |
| 18696 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18697 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18698 | |
| 18699 | } // namespace |
| 18700 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18701 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18702 | : public HttpNetworkTransactionTest { |
| 18703 | protected: |
| 18704 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18705 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18706 | auto network_error_logging_service = |
| 18707 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18708 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18709 | session_deps_.network_error_logging_service = |
| 18710 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18711 | |
| 18712 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18713 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18714 | |
| 18715 | request_.method = "GET"; |
| 18716 | request_.url = GURL(url_); |
| 18717 | request_.extra_headers = extra_headers_; |
| 18718 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18719 | request_.traffic_annotation = |
| 18720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18721 | } |
| 18722 | |
| 18723 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18724 | return test_network_error_logging_service_; |
| 18725 | } |
| 18726 | |
| 18727 | void clear_network_error_logging_service() { |
| 18728 | session_deps_.network_error_logging_service.reset(); |
| 18729 | test_network_error_logging_service_ = nullptr; |
| 18730 | } |
| 18731 | |
| 18732 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18733 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18734 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18735 | MockWrite data_writes[] = { |
| 18736 | MockWrite("GET / HTTP/1.1\r\n" |
| 18737 | "Host: www.example.org\r\n" |
| 18738 | "Connection: keep-alive\r\n"), |
| 18739 | MockWrite(ASYNC, extra_header_string.data(), |
| 18740 | extra_header_string.size()), |
| 18741 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18742 | MockRead data_reads[] = { |
| 18743 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18744 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18745 | MockRead("\r\n"), |
| 18746 | MockRead("hello world"), |
| 18747 | MockRead(SYNCHRONOUS, OK), |
| 18748 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18749 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18750 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18751 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18752 | |
| 18753 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18754 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18755 | ssl.ssl_info.cert = |
| 18756 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18757 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18758 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18760 | } |
| 18761 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18762 | TestCompletionCallback callback; |
| 18763 | auto session = CreateSession(&session_deps_); |
| 18764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18765 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18766 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18767 | |
| 18768 | std::string response_data; |
| 18769 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18770 | EXPECT_EQ("hello world", response_data); |
| 18771 | } |
| 18772 | |
| 18773 | void CheckReport(size_t index, |
| 18774 | int status_code, |
| 18775 | int error_type, |
| 18776 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18777 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18778 | |
| 18779 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18780 | network_error_logging_service()->errors()[index]; |
| 18781 | EXPECT_EQ(url_, error.uri); |
| 18782 | EXPECT_EQ(kReferrer, error.referrer); |
| 18783 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18784 | EXPECT_EQ(server_ip, error.server_ip); |
| 18785 | EXPECT_EQ("http/1.1", error.protocol); |
| 18786 | EXPECT_EQ("GET", error.method); |
| 18787 | EXPECT_EQ(status_code, error.status_code); |
| 18788 | EXPECT_EQ(error_type, error.type); |
| 18789 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18790 | } |
| 18791 | |
| 18792 | protected: |
| 18793 | std::string url_ = "https://www.example.org/"; |
| 18794 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18795 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18796 | HttpRequestHeaders extra_headers_; |
| 18797 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18798 | |
| 18799 | private: |
| 18800 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18801 | }; |
| 18802 | |
| 18803 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18804 | DontProcessNelHeaderNoService) { |
| 18805 | base::HistogramTester histograms; |
| 18806 | clear_network_error_logging_service(); |
| 18807 | RequestPolicy(); |
| 18808 | histograms.ExpectBucketCount( |
| 18809 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18810 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18811 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18812 | 1); |
| 18813 | } |
| 18814 | |
| 18815 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18816 | DontProcessNelHeaderHttp) { |
| 18817 | base::HistogramTester histograms; |
| 18818 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18819 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18820 | RequestPolicy(); |
| 18821 | histograms.ExpectBucketCount( |
| 18822 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18823 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18824 | } |
| 18825 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18826 | // Don't set NEL policies received on a proxied connection. |
| 18827 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18828 | DontProcessNelHeaderProxy) { |
| 18829 | session_deps_.proxy_resolution_service = |
| 18830 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18831 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18832 | BoundTestNetLog log; |
| 18833 | session_deps_.net_log = log.bound().net_log(); |
| 18834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18835 | |
| 18836 | HttpRequestInfo request; |
| 18837 | request.method = "GET"; |
| 18838 | request.url = GURL("https://www.example.org/"); |
| 18839 | request.traffic_annotation = |
| 18840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18841 | |
| 18842 | // Since we have proxy, should try to establish tunnel. |
| 18843 | MockWrite data_writes1[] = { |
| 18844 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18845 | "Host: www.example.org:443\r\n" |
| 18846 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18847 | |
| 18848 | MockWrite("GET / HTTP/1.1\r\n" |
| 18849 | "Host: www.example.org\r\n" |
| 18850 | "Connection: keep-alive\r\n\r\n"), |
| 18851 | }; |
| 18852 | |
| 18853 | MockRead data_reads1[] = { |
| 18854 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18855 | |
| 18856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18857 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18858 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18859 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18860 | MockRead(SYNCHRONOUS, OK), |
| 18861 | }; |
| 18862 | |
| 18863 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18864 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18865 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18866 | ssl.ssl_info.cert = |
| 18867 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18868 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18869 | ssl.ssl_info.cert_status = 0; |
| 18870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18871 | |
| 18872 | TestCompletionCallback callback1; |
| 18873 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18874 | |
| 18875 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18877 | |
| 18878 | rv = callback1.WaitForResult(); |
| 18879 | EXPECT_THAT(rv, IsOk()); |
| 18880 | |
| 18881 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18882 | ASSERT_TRUE(response); |
| 18883 | EXPECT_EQ(200, response->headers->response_code()); |
| 18884 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18885 | |
| 18886 | // No NEL header was set. |
| 18887 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18888 | } |
| 18889 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18890 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18891 | RequestPolicy(); |
| 18892 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18893 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18894 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18895 | header.origin); |
| 18896 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18897 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18898 | } |
| 18899 | |
| 18900 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18901 | DontProcessNelHeaderInvalidHttps) { |
| 18902 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18903 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18904 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18905 | histograms.ExpectBucketCount( |
| 18906 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18907 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18908 | 1); |
| 18909 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18910 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18911 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18912 | RequestPolicy(); |
| 18913 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18914 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18915 | } |
| 18916 | |
| 18917 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18918 | CreateReportErrorAfterStart) { |
| 18919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18920 | auto trans = |
| 18921 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18922 | |
| 18923 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18924 | StaticSocketDataProvider data; |
| 18925 | data.set_connect_data(mock_connect); |
| 18926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18927 | |
| 18928 | TestCompletionCallback callback; |
| 18929 | |
| 18930 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18931 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18932 | |
| 18933 | trans.reset(); |
| 18934 | |
| 18935 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18936 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18937 | IPAddress() /* server_ip */); |
| 18938 | } |
| 18939 | |
| 18940 | // Same as above except the error is ASYNC |
| 18941 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18942 | CreateReportErrorAfterStartAsync) { |
| 18943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18944 | auto trans = |
| 18945 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18946 | |
| 18947 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18948 | StaticSocketDataProvider data; |
| 18949 | data.set_connect_data(mock_connect); |
| 18950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18951 | |
| 18952 | TestCompletionCallback callback; |
| 18953 | |
| 18954 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18955 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18956 | |
| 18957 | trans.reset(); |
| 18958 | |
| 18959 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18960 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18961 | IPAddress() /* server_ip */); |
| 18962 | } |
| 18963 | |
| 18964 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18965 | CreateReportReadBodyError) { |
| 18966 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18967 | MockWrite data_writes[] = { |
| 18968 | MockWrite("GET / HTTP/1.1\r\n" |
| 18969 | "Host: www.example.org\r\n" |
| 18970 | "Connection: keep-alive\r\n"), |
| 18971 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18972 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18973 | MockRead data_reads[] = { |
| 18974 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18975 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18976 | MockRead("hello world"), |
| 18977 | MockRead(SYNCHRONOUS, OK), |
| 18978 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18979 | |
| 18980 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18981 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18982 | |
| 18983 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18985 | |
| 18986 | // Log start time |
| 18987 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18988 | |
| 18989 | TestCompletionCallback callback; |
| 18990 | auto session = CreateSession(&session_deps_); |
| 18991 | auto trans = |
| 18992 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18993 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18994 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18995 | |
| 18996 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18997 | ASSERT_TRUE(response); |
| 18998 | |
| 18999 | EXPECT_TRUE(response->headers); |
| 19000 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19001 | |
| 19002 | std::string response_data; |
| 19003 | rv = ReadTransaction(trans.get(), &response_data); |
| 19004 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19005 | |
| 19006 | trans.reset(); |
| 19007 | |
| 19008 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19009 | |
| 19010 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19011 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19012 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19013 | network_error_logging_service()->errors()[0]; |
| 19014 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19015 | } |
| 19016 | |
| 19017 | // Same as above except the final read is ASYNC. |
| 19018 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19019 | CreateReportReadBodyErrorAsync) { |
| 19020 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19021 | MockWrite data_writes[] = { |
| 19022 | MockWrite("GET / HTTP/1.1\r\n" |
| 19023 | "Host: www.example.org\r\n" |
| 19024 | "Connection: keep-alive\r\n"), |
| 19025 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19026 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19027 | MockRead data_reads[] = { |
| 19028 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19029 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 19030 | MockRead("hello world"), |
| 19031 | MockRead(ASYNC, OK), |
| 19032 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19033 | |
| 19034 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19035 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19036 | |
| 19037 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19039 | |
| 19040 | // Log start time |
| 19041 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19042 | |
| 19043 | TestCompletionCallback callback; |
| 19044 | auto session = CreateSession(&session_deps_); |
| 19045 | auto trans = |
| 19046 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19047 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19048 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19049 | |
| 19050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19051 | ASSERT_TRUE(response); |
| 19052 | |
| 19053 | EXPECT_TRUE(response->headers); |
| 19054 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19055 | |
| 19056 | std::string response_data; |
| 19057 | rv = ReadTransaction(trans.get(), &response_data); |
| 19058 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19059 | |
| 19060 | trans.reset(); |
| 19061 | |
| 19062 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19063 | |
| 19064 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19065 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19066 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19067 | network_error_logging_service()->errors()[0]; |
| 19068 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19069 | } |
| 19070 | |
| 19071 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19072 | CreateReportRestartWithAuth) { |
| 19073 | std::string extra_header_string = extra_headers_.ToString(); |
| 19074 | static const base::TimeDelta kSleepDuration = |
| 19075 | base::TimeDelta::FromMilliseconds(10); |
| 19076 | |
| 19077 | MockWrite data_writes1[] = { |
| 19078 | MockWrite("GET / HTTP/1.1\r\n" |
| 19079 | "Host: www.example.org\r\n" |
| 19080 | "Connection: keep-alive\r\n"), |
| 19081 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19082 | }; |
| 19083 | |
| 19084 | MockRead data_reads1[] = { |
| 19085 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 19086 | // Give a couple authenticate options (only the middle one is actually |
| 19087 | // supported). |
| 19088 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 19089 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19090 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 19091 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19092 | // Large content-length -- won't matter, as connection will be reset. |
| 19093 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 19094 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 19095 | }; |
| 19096 | |
| 19097 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19098 | // be issuing -- the final header line contains the credentials. |
| 19099 | MockWrite data_writes2[] = { |
| 19100 | MockWrite("GET / HTTP/1.1\r\n" |
| 19101 | "Host: www.example.org\r\n" |
| 19102 | "Connection: keep-alive\r\n" |
| 19103 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 19104 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19105 | }; |
| 19106 | |
| 19107 | // Lastly, the server responds with the actual content. |
| 19108 | MockRead data_reads2[] = { |
| 19109 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19110 | MockRead("hello world"), |
| 19111 | MockRead(SYNCHRONOUS, OK), |
| 19112 | }; |
| 19113 | |
| 19114 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19115 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19117 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19118 | |
| 19119 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19121 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19123 | |
| 19124 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19125 | base::TimeTicks restart_time; |
| 19126 | |
| 19127 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19128 | auto trans = |
| 19129 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19130 | |
| 19131 | TestCompletionCallback callback1; |
| 19132 | |
| 19133 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19134 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19135 | |
| 19136 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19137 | |
| 19138 | TestCompletionCallback callback2; |
| 19139 | |
| 19140 | // Wait 10 ms then restart with auth |
| 19141 | FastForwardBy(kSleepDuration); |
| 19142 | restart_time = base::TimeTicks::Now(); |
| 19143 | rv = |
| 19144 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19145 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19146 | |
| 19147 | std::string response_data; |
| 19148 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19149 | EXPECT_EQ("hello world", response_data); |
| 19150 | |
| 19151 | trans.reset(); |
| 19152 | |
| 19153 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 19154 | // retry. Note that we don't report the error draining the body, as the first |
| 19155 | // request already generated a report for the auth challenge. |
| 19156 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 19157 | |
| 19158 | // Check error report contents |
| 19159 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 19160 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 19161 | |
| 19162 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19163 | network_error_logging_service()->errors()[0]; |
| 19164 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19165 | network_error_logging_service()->errors()[1]; |
| 19166 | |
| 19167 | // Sanity-check elapsed time values |
| 19168 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19169 | // Check that the start time is refreshed when restarting with auth. |
| 19170 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19171 | } |
| 19172 | |
| 19173 | // Same as above, except draining the body before restarting fails |
| 19174 | // asynchronously. |
| 19175 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19176 | CreateReportRestartWithAuthAsync) { |
| 19177 | std::string extra_header_string = extra_headers_.ToString(); |
| 19178 | static const base::TimeDelta kSleepDuration = |
| 19179 | base::TimeDelta::FromMilliseconds(10); |
| 19180 | |
| 19181 | MockWrite data_writes1[] = { |
| 19182 | MockWrite("GET / HTTP/1.1\r\n" |
| 19183 | "Host: www.example.org\r\n" |
| 19184 | "Connection: keep-alive\r\n"), |
| 19185 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19186 | }; |
| 19187 | |
| 19188 | MockRead data_reads1[] = { |
| 19189 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 19190 | // Give a couple authenticate options (only the middle one is actually |
| 19191 | // supported). |
| 19192 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 19193 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19194 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 19195 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19196 | // Large content-length -- won't matter, as connection will be reset. |
| 19197 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 19198 | MockRead(ASYNC, ERR_FAILED), |
| 19199 | }; |
| 19200 | |
| 19201 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19202 | // be issuing -- the final header line contains the credentials. |
| 19203 | MockWrite data_writes2[] = { |
| 19204 | MockWrite("GET / HTTP/1.1\r\n" |
| 19205 | "Host: www.example.org\r\n" |
| 19206 | "Connection: keep-alive\r\n" |
| 19207 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 19208 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19209 | }; |
| 19210 | |
| 19211 | // Lastly, the server responds with the actual content. |
| 19212 | MockRead data_reads2[] = { |
| 19213 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19214 | MockRead("hello world"), |
| 19215 | MockRead(SYNCHRONOUS, OK), |
| 19216 | }; |
| 19217 | |
| 19218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19219 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19222 | |
| 19223 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19225 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19227 | |
| 19228 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19229 | base::TimeTicks restart_time; |
| 19230 | |
| 19231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19232 | auto trans = |
| 19233 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19234 | |
| 19235 | TestCompletionCallback callback1; |
| 19236 | |
| 19237 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19238 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19239 | |
| 19240 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19241 | |
| 19242 | TestCompletionCallback callback2; |
| 19243 | |
| 19244 | // Wait 10 ms then restart with auth |
| 19245 | FastForwardBy(kSleepDuration); |
| 19246 | restart_time = base::TimeTicks::Now(); |
| 19247 | rv = |
| 19248 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19249 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19250 | |
| 19251 | std::string response_data; |
| 19252 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19253 | EXPECT_EQ("hello world", response_data); |
| 19254 | |
| 19255 | trans.reset(); |
| 19256 | |
| 19257 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 19258 | // retry. Note that we don't report the error draining the body, as the first |
| 19259 | // request already generated a report for the auth challenge. |
| 19260 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 19261 | |
| 19262 | // Check error report contents |
| 19263 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 19264 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 19265 | |
| 19266 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19267 | network_error_logging_service()->errors()[0]; |
| 19268 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19269 | network_error_logging_service()->errors()[1]; |
| 19270 | |
| 19271 | // Sanity-check elapsed time values |
| 19272 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19273 | // Check that the start time is refreshed when restarting with auth. |
| 19274 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19275 | } |
| 19276 | |
| 19277 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19278 | CreateReportRetryKeepAliveConnectionReset) { |
| 19279 | std::string extra_header_string = extra_headers_.ToString(); |
| 19280 | MockWrite data_writes1[] = { |
| 19281 | MockWrite("GET / HTTP/1.1\r\n" |
| 19282 | "Host: www.example.org\r\n" |
| 19283 | "Connection: keep-alive\r\n"), |
| 19284 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19285 | MockWrite("GET / HTTP/1.1\r\n" |
| 19286 | "Host: www.example.org\r\n" |
| 19287 | "Connection: keep-alive\r\n"), |
| 19288 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19289 | }; |
| 19290 | |
| 19291 | MockRead data_reads1[] = { |
| 19292 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19293 | MockRead("hello"), |
| 19294 | // Connection is reset |
| 19295 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19296 | }; |
| 19297 | |
| 19298 | // Successful retry |
| 19299 | MockRead data_reads2[] = { |
| 19300 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19301 | MockRead("world"), |
| 19302 | MockRead(ASYNC, OK), |
| 19303 | }; |
| 19304 | |
| 19305 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19306 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19307 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19308 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19309 | |
| 19310 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19311 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19312 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19314 | |
| 19315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19316 | auto trans1 = |
| 19317 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19318 | |
| 19319 | TestCompletionCallback callback1; |
| 19320 | |
| 19321 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19322 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19323 | |
| 19324 | std::string response_data; |
| 19325 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19326 | EXPECT_EQ("hello", response_data); |
| 19327 | |
| 19328 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19329 | |
| 19330 | auto trans2 = |
| 19331 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19332 | |
| 19333 | TestCompletionCallback callback2; |
| 19334 | |
| 19335 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19336 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19337 | |
| 19338 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19339 | EXPECT_EQ("world", response_data); |
| 19340 | |
| 19341 | trans1.reset(); |
| 19342 | trans2.reset(); |
| 19343 | |
| 19344 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19345 | // the second request, then an OK report from the successful retry. |
| 19346 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19347 | |
| 19348 | // Check error report contents |
| 19349 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19350 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19351 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19352 | } |
| 19353 | |
| 19354 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19355 | CreateReportRetryKeepAlive408) { |
| 19356 | std::string extra_header_string = extra_headers_.ToString(); |
| 19357 | MockWrite data_writes1[] = { |
| 19358 | MockWrite("GET / HTTP/1.1\r\n" |
| 19359 | "Host: www.example.org\r\n" |
| 19360 | "Connection: keep-alive\r\n"), |
| 19361 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19362 | MockWrite("GET / HTTP/1.1\r\n" |
| 19363 | "Host: www.example.org\r\n" |
| 19364 | "Connection: keep-alive\r\n"), |
| 19365 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19366 | }; |
| 19367 | |
| 19368 | MockRead data_reads1[] = { |
| 19369 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19370 | MockRead("hello"), |
| 19371 | // 408 Request Timeout |
| 19372 | MockRead(SYNCHRONOUS, |
| 19373 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19374 | "Connection: Keep-Alive\r\n" |
| 19375 | "Content-Length: 6\r\n\r\n" |
| 19376 | "Pickle"), |
| 19377 | }; |
| 19378 | |
| 19379 | // Successful retry |
| 19380 | MockRead data_reads2[] = { |
| 19381 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19382 | MockRead("world"), |
| 19383 | MockRead(ASYNC, OK), |
| 19384 | }; |
| 19385 | |
| 19386 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19387 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19388 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19389 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19390 | |
| 19391 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19393 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19395 | |
| 19396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19397 | auto trans1 = |
| 19398 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19399 | |
| 19400 | TestCompletionCallback callback1; |
| 19401 | |
| 19402 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19403 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19404 | |
| 19405 | std::string response_data; |
| 19406 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19407 | EXPECT_EQ("hello", response_data); |
| 19408 | |
| 19409 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19410 | |
| 19411 | auto trans2 = |
| 19412 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19413 | |
| 19414 | TestCompletionCallback callback2; |
| 19415 | |
| 19416 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19417 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19418 | |
| 19419 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19420 | EXPECT_EQ("world", response_data); |
| 19421 | |
| 19422 | trans1.reset(); |
| 19423 | trans2.reset(); |
| 19424 | |
| 19425 | // One 200 report from first request, then a 408 report from |
| 19426 | // the second request, then a 200 report from the successful retry. |
| 19427 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19428 | |
| 19429 | // Check error report contents |
| 19430 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19431 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19432 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19433 | } |
| 19434 | |
| 19435 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19436 | CreateReportRetry421WithoutConnectionPooling) { |
| 19437 | // Two hosts resolve to the same IP address. |
| 19438 | const std::string ip_addr = "1.2.3.4"; |
| 19439 | IPAddress ip; |
| 19440 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19441 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19442 | |
| 19443 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19444 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19445 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19446 | |
| 19447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19448 | |
| 19449 | // Two requests on the first connection. |
| 19450 | spdy::SpdySerializedFrame req1( |
| 19451 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19452 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19453 | spdy::SpdySerializedFrame req2( |
| 19454 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19455 | spdy::SpdySerializedFrame rst( |
| 19456 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19457 | MockWrite writes1[] = { |
| 19458 | CreateMockWrite(req1, 0), |
| 19459 | CreateMockWrite(req2, 3), |
| 19460 | CreateMockWrite(rst, 6), |
| 19461 | }; |
| 19462 | |
| 19463 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19464 | spdy::SpdySerializedFrame resp1( |
| 19465 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19466 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19467 | spdy::SpdyHeaderBlock response_headers; |
| 19468 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19469 | spdy::SpdySerializedFrame resp2( |
| 19470 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19471 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19472 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19473 | |
| 19474 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19475 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19476 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19477 | |
| 19478 | AddSSLSocketData(); |
| 19479 | |
| 19480 | // Retry the second request on a second connection. |
| 19481 | SpdyTestUtil spdy_util2; |
| 19482 | spdy::SpdySerializedFrame req3( |
| 19483 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19484 | MockWrite writes2[] = { |
| 19485 | CreateMockWrite(req3, 0), |
| 19486 | }; |
| 19487 | |
| 19488 | spdy::SpdySerializedFrame resp3( |
| 19489 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19490 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19491 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19492 | MockRead(ASYNC, 0, 3)}; |
| 19493 | |
| 19494 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19495 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19496 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19497 | |
| 19498 | AddSSLSocketData(); |
| 19499 | |
| 19500 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19501 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19502 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19503 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19504 | |
| 19505 | HttpRequestInfo request1; |
| 19506 | request1.method = "GET"; |
| 19507 | request1.url = GURL("https://www.example.org/"); |
| 19508 | request1.load_flags = 0; |
| 19509 | request1.traffic_annotation = |
| 19510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19511 | auto trans1 = |
| 19512 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19513 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19514 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19515 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19516 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19517 | |
| 19518 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19519 | ASSERT_TRUE(response); |
| 19520 | ASSERT_TRUE(response->headers); |
| 19521 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19522 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19523 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19524 | std::string response_data; |
| 19525 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19526 | EXPECT_EQ("hello!", response_data); |
| 19527 | |
| 19528 | trans1.reset(); |
| 19529 | |
| 19530 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19531 | |
| 19532 | HttpRequestInfo request2; |
| 19533 | request2.method = "GET"; |
| 19534 | request2.url = GURL("https://mail.example.org/"); |
| 19535 | request2.load_flags = 0; |
| 19536 | request2.traffic_annotation = |
| 19537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19538 | auto trans2 = |
| 19539 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19540 | |
| 19541 | BoundTestNetLog log; |
| 19542 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19543 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19544 | |
| 19545 | response = trans2->GetResponseInfo(); |
| 19546 | ASSERT_TRUE(response); |
| 19547 | ASSERT_TRUE(response->headers); |
| 19548 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19549 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19550 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19551 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19552 | EXPECT_EQ("hello!", response_data); |
| 19553 | |
| 19554 | trans2.reset(); |
| 19555 | |
| 19556 | // One 200 report from the first request, then a 421 report from the |
| 19557 | // second request, then a 200 report from the successful retry. |
| 19558 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19559 | |
| 19560 | // Check error report contents |
| 19561 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19562 | network_error_logging_service()->errors()[0]; |
| 19563 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19564 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19565 | EXPECT_EQ("", error1.user_agent); |
| 19566 | EXPECT_EQ(ip, error1.server_ip); |
| 19567 | EXPECT_EQ("h2", error1.protocol); |
| 19568 | EXPECT_EQ("GET", error1.method); |
| 19569 | EXPECT_EQ(200, error1.status_code); |
| 19570 | EXPECT_EQ(OK, error1.type); |
| 19571 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19572 | |
| 19573 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19574 | network_error_logging_service()->errors()[1]; |
| 19575 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19576 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19577 | EXPECT_EQ("", error2.user_agent); |
| 19578 | EXPECT_EQ(ip, error2.server_ip); |
| 19579 | EXPECT_EQ("h2", error2.protocol); |
| 19580 | EXPECT_EQ("GET", error2.method); |
| 19581 | EXPECT_EQ(421, error2.status_code); |
| 19582 | EXPECT_EQ(OK, error2.type); |
| 19583 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19584 | |
| 19585 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19586 | network_error_logging_service()->errors()[2]; |
| 19587 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19588 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19589 | EXPECT_EQ("", error3.user_agent); |
| 19590 | EXPECT_EQ(ip, error3.server_ip); |
| 19591 | EXPECT_EQ("h2", error3.protocol); |
| 19592 | EXPECT_EQ("GET", error3.method); |
| 19593 | EXPECT_EQ(200, error3.status_code); |
| 19594 | EXPECT_EQ(OK, error3.type); |
| 19595 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19596 | } |
| 19597 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19598 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19599 | CreateReportCancelAfterStart) { |
| 19600 | StaticSocketDataProvider data; |
| 19601 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19603 | |
| 19604 | TestCompletionCallback callback; |
| 19605 | auto session = CreateSession(&session_deps_); |
| 19606 | auto trans = |
| 19607 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19608 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19609 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19610 | |
| 19611 | // Cancel after start. |
| 19612 | trans.reset(); |
| 19613 | |
| 19614 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19615 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19616 | IPAddress() /* server_ip */); |
| 19617 | } |
| 19618 | |
| 19619 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19620 | CreateReportCancelBeforeReadingBody) { |
| 19621 | std::string extra_header_string = extra_headers_.ToString(); |
| 19622 | MockWrite data_writes[] = { |
| 19623 | MockWrite("GET / HTTP/1.1\r\n" |
| 19624 | "Host: www.example.org\r\n" |
| 19625 | "Connection: keep-alive\r\n"), |
| 19626 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19627 | }; |
| 19628 | MockRead data_reads[] = { |
| 19629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19630 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19631 | }; |
| 19632 | |
| 19633 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19635 | |
| 19636 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19637 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19638 | |
| 19639 | TestCompletionCallback callback; |
| 19640 | auto session = CreateSession(&session_deps_); |
| 19641 | auto trans = |
| 19642 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19643 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19644 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19645 | |
| 19646 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19647 | ASSERT_TRUE(response); |
| 19648 | |
| 19649 | EXPECT_TRUE(response->headers); |
| 19650 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19651 | |
| 19652 | // Cancel before reading the body. |
| 19653 | trans.reset(); |
| 19654 | |
| 19655 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19656 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19657 | } |
| 19658 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19659 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19660 | base::HistogramTester histograms; |
| 19661 | RequestPolicy(); |
| 19662 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19663 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19664 | |
| 19665 | // Make HTTP request |
| 19666 | std::string extra_header_string = extra_headers_.ToString(); |
| 19667 | MockRead data_reads[] = { |
| 19668 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19669 | MockRead("hello world"), |
| 19670 | MockRead(SYNCHRONOUS, OK), |
| 19671 | }; |
| 19672 | MockWrite data_writes[] = { |
| 19673 | MockWrite("GET / HTTP/1.1\r\n" |
| 19674 | "Host: www.example.org\r\n" |
| 19675 | "Connection: keep-alive\r\n"), |
| 19676 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19677 | }; |
| 19678 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19679 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19680 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19681 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19682 | // Insecure url |
| 19683 | url_ = "http://www.example.org/"; |
| 19684 | request_.url = GURL(url_); |
| 19685 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19686 | TestCompletionCallback callback; |
| 19687 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19688 | auto trans = |
| 19689 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19690 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19691 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19692 | |
| 19693 | std::string response_data; |
| 19694 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19695 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19696 | |
| 19697 | // Insecure request does not generate a report |
| 19698 | histograms.ExpectBucketCount( |
| 19699 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19700 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19701 | |
| 19702 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19703 | } |
| 19704 | |
| 19705 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19706 | DontCreateReportHttpError) { |
| 19707 | base::HistogramTester histograms; |
| 19708 | RequestPolicy(); |
| 19709 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19710 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19711 | |
| 19712 | // Make HTTP request that fails |
| 19713 | MockRead data_reads[] = { |
| 19714 | MockRead("hello world"), |
| 19715 | MockRead(SYNCHRONOUS, OK), |
| 19716 | }; |
| 19717 | |
| 19718 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19720 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19721 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19722 | request_.url = GURL(url_); |
| 19723 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19725 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19726 | auto trans = |
| 19727 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19728 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19729 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19730 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19731 | |
| 19732 | // Insecure request does not generate a report, regardless of existence of a |
| 19733 | // policy for the origin. |
| 19734 | histograms.ExpectBucketCount( |
| 19735 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19736 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19737 | |
| 19738 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19739 | } |
| 19740 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19741 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19742 | // proxy. |
| 19743 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19744 | HttpRequestInfo request; |
| 19745 | request.method = "GET"; |
| 19746 | request.url = GURL("https://www.example.org/"); |
| 19747 | request.traffic_annotation = |
| 19748 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19749 | |
| 19750 | // Configure against proxy server "myproxy:70". |
| 19751 | session_deps_.proxy_resolution_service = |
| 19752 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19753 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19755 | |
| 19756 | // Since we have proxy, should try to establish tunnel. |
| 19757 | MockWrite data_writes1[] = { |
| 19758 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19759 | "Host: www.example.org:443\r\n" |
| 19760 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19761 | }; |
| 19762 | |
| 19763 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19764 | // connection. |
| 19765 | MockRead data_reads1[] = { |
| 19766 | // No credentials. |
| 19767 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19768 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19769 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19770 | }; |
| 19771 | |
| 19772 | MockWrite data_writes2[] = { |
| 19773 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19774 | // be issuing -- the final header line contains the credentials. |
| 19775 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19776 | "Host: www.example.org:443\r\n" |
| 19777 | "Proxy-Connection: keep-alive\r\n" |
| 19778 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19779 | |
| 19780 | MockWrite("GET / HTTP/1.1\r\n" |
| 19781 | "Host: www.example.org\r\n" |
| 19782 | "Connection: keep-alive\r\n\r\n"), |
| 19783 | }; |
| 19784 | |
| 19785 | MockRead data_reads2[] = { |
| 19786 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19787 | |
| 19788 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19789 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19790 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19791 | MockRead(SYNCHRONOUS, "hello"), |
| 19792 | }; |
| 19793 | |
| 19794 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19796 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19797 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19798 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19799 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19800 | |
| 19801 | TestCompletionCallback callback1; |
| 19802 | |
| 19803 | auto trans = |
| 19804 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19805 | |
| 19806 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19807 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19808 | |
| 19809 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19810 | EXPECT_EQ(407, response->headers->response_code()); |
| 19811 | |
| 19812 | std::string response_data; |
| 19813 | rv = ReadTransaction(trans.get(), &response_data); |
| 19814 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19815 | |
| 19816 | // No NEL report is generated for the 407. |
| 19817 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19818 | |
| 19819 | TestCompletionCallback callback2; |
| 19820 | |
| 19821 | rv = |
| 19822 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19823 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19824 | |
| 19825 | response = trans->GetResponseInfo(); |
| 19826 | EXPECT_EQ(200, response->headers->response_code()); |
| 19827 | |
| 19828 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19829 | EXPECT_EQ("hello", response_data); |
| 19830 | |
| 19831 | trans.reset(); |
| 19832 | |
| 19833 | // No NEL report is generated because we are behind a proxy. |
| 19834 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19835 | } |
| 19836 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19837 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19838 | ReportContainsUploadDepth) { |
| 19839 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19840 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19841 | RequestPolicy(); |
| 19842 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19843 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19844 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19845 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19846 | } |
| 19847 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19848 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19849 | std::string extra_header_string = extra_headers_.ToString(); |
| 19850 | static const base::TimeDelta kSleepDuration = |
| 19851 | base::TimeDelta::FromMilliseconds(10); |
| 19852 | |
| 19853 | std::vector<MockWrite> data_writes = { |
| 19854 | MockWrite(ASYNC, 0, |
| 19855 | "GET / HTTP/1.1\r\n" |
| 19856 | "Host: www.example.org\r\n" |
| 19857 | "Connection: keep-alive\r\n"), |
| 19858 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19859 | }; |
| 19860 | |
| 19861 | std::vector<MockRead> data_reads = { |
| 19862 | // Write one byte of the status line, followed by a pause. |
| 19863 | MockRead(ASYNC, 2, "H"), |
| 19864 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19865 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19866 | MockRead(ASYNC, 5, "hello world"), |
| 19867 | MockRead(SYNCHRONOUS, OK, 6), |
| 19868 | }; |
| 19869 | |
| 19870 | SequencedSocketData data(data_reads, data_writes); |
| 19871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19872 | |
| 19873 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19875 | |
| 19876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19877 | |
| 19878 | auto trans = |
| 19879 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19880 | |
| 19881 | TestCompletionCallback callback; |
| 19882 | |
| 19883 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19885 | |
| 19886 | data.RunUntilPaused(); |
| 19887 | ASSERT_TRUE(data.IsPaused()); |
| 19888 | FastForwardBy(kSleepDuration); |
| 19889 | data.Resume(); |
| 19890 | |
| 19891 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19892 | |
| 19893 | std::string response_data; |
| 19894 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19895 | EXPECT_EQ("hello world", response_data); |
| 19896 | |
| 19897 | trans.reset(); |
| 19898 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19899 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19900 | |
| 19901 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19902 | |
| 19903 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19904 | network_error_logging_service()->errors()[0]; |
| 19905 | |
| 19906 | // Sanity-check elapsed time in error report |
| 19907 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19908 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19909 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19910 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19911 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 19912 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 19913 | HttpRequestInfo request; |
| 19914 | request.method = "GET"; |
| 19915 | request.url = GURL("http://example.org/"); |
| 19916 | |
| 19917 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 19918 | |
| 19919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19921 | TestCompletionCallback callback1; |
| 19922 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 19923 | |
| 19924 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 19925 | } |
| 19926 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19927 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 19928 | HttpRequestInfo request; |
| 19929 | request.method = "GET"; |
| 19930 | request.url = GURL("https://www.example.org/"); |
| 19931 | request.traffic_annotation = |
| 19932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19933 | |
| 19934 | MockWrite data_writes[] = { |
| 19935 | MockWrite("GET / HTTP/1.1\r\n" |
| 19936 | "Host: www.example.org\r\n" |
| 19937 | "Connection: keep-alive\r\n\r\n"), |
| 19938 | }; |
| 19939 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19940 | MockRead data_reads[] = { |
| 19941 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19942 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19943 | MockRead(SYNCHRONOUS, "1"), |
| 19944 | }; |
| 19945 | |
| 19946 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19948 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19949 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19950 | session_deps_.enable_early_data = true; |
| 19951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19952 | |
| 19953 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19954 | |
| 19955 | TestCompletionCallback callback; |
| 19956 | auto trans = |
| 19957 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19958 | |
| 19959 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19961 | |
| 19962 | rv = callback.WaitForResult(); |
| 19963 | EXPECT_THAT(rv, IsOk()); |
| 19964 | |
| 19965 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19966 | ASSERT_TRUE(response); |
| 19967 | ASSERT_TRUE(response->headers); |
| 19968 | EXPECT_EQ(200, response->headers->response_code()); |
| 19969 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19970 | |
| 19971 | // Check that ConfirmHandshake wasn't called. |
| 19972 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 19973 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 19974 | |
| 19975 | trans.reset(); |
| 19976 | |
| 19977 | session->CloseAllConnections(); |
| 19978 | } |
| 19979 | |
| 19980 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 19981 | HttpRequestInfo request; |
| 19982 | request.method = "POST"; |
| 19983 | request.url = GURL("https://www.example.org/"); |
| 19984 | request.traffic_annotation = |
| 19985 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19986 | |
| 19987 | MockWrite data_writes[] = { |
| 19988 | MockWrite(SYNCHRONOUS, |
| 19989 | "POST / HTTP/1.1\r\n" |
| 19990 | "Host: www.example.org\r\n" |
| 19991 | "Connection: keep-alive\r\n" |
| 19992 | "Content-Length: 0\r\n\r\n"), |
| 19993 | }; |
| 19994 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19995 | MockRead data_reads[] = { |
| 19996 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19997 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19998 | MockRead(SYNCHRONOUS, "1"), |
| 19999 | }; |
| 20000 | |
| 20001 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20002 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20003 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20004 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20005 | session_deps_.enable_early_data = true; |
| 20006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20007 | |
| 20008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20009 | |
| 20010 | TestCompletionCallback callback; |
| 20011 | auto trans = |
| 20012 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20013 | |
| 20014 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20016 | |
| 20017 | rv = callback.WaitForResult(); |
| 20018 | EXPECT_THAT(rv, IsOk()); |
| 20019 | |
| 20020 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20021 | ASSERT_TRUE(response); |
| 20022 | ASSERT_TRUE(response->headers); |
| 20023 | EXPECT_EQ(200, response->headers->response_code()); |
| 20024 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20025 | |
| 20026 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20027 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20028 | |
| 20029 | trans.reset(); |
| 20030 | |
| 20031 | session->CloseAllConnections(); |
| 20032 | } |
| 20033 | |
| 20034 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 20035 | HttpRequestInfo request; |
| 20036 | request.method = "POST"; |
| 20037 | request.url = GURL("https://www.example.org/"); |
| 20038 | request.traffic_annotation = |
| 20039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20040 | |
| 20041 | MockWrite data_writes[] = { |
| 20042 | MockWrite(ASYNC, |
| 20043 | "POST / HTTP/1.1\r\n" |
| 20044 | "Host: www.example.org\r\n" |
| 20045 | "Connection: keep-alive\r\n" |
| 20046 | "Content-Length: 0\r\n\r\n"), |
| 20047 | }; |
| 20048 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20049 | MockRead data_reads[] = { |
| 20050 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20051 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20052 | MockRead(SYNCHRONOUS, "1"), |
| 20053 | }; |
| 20054 | |
| 20055 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20057 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20058 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20059 | session_deps_.enable_early_data = true; |
| 20060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20061 | |
| 20062 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20063 | |
| 20064 | TestCompletionCallback callback; |
| 20065 | auto trans = |
| 20066 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20067 | |
| 20068 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20070 | |
| 20071 | rv = callback.WaitForResult(); |
| 20072 | EXPECT_THAT(rv, IsOk()); |
| 20073 | |
| 20074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20075 | ASSERT_TRUE(response); |
| 20076 | ASSERT_TRUE(response->headers); |
| 20077 | EXPECT_EQ(200, response->headers->response_code()); |
| 20078 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20079 | |
| 20080 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20081 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20082 | |
| 20083 | trans.reset(); |
| 20084 | |
| 20085 | session->CloseAllConnections(); |
| 20086 | } |
| 20087 | |
| 20088 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 20089 | HttpRequestInfo request; |
| 20090 | request.method = "POST"; |
| 20091 | request.url = GURL("https://www.example.org/"); |
| 20092 | request.traffic_annotation = |
| 20093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20094 | |
| 20095 | MockWrite data_writes[] = { |
| 20096 | MockWrite(SYNCHRONOUS, |
| 20097 | "POST / HTTP/1.1\r\n" |
| 20098 | "Host: www.example.org\r\n" |
| 20099 | "Connection: keep-alive\r\n" |
| 20100 | "Content-Length: 0\r\n\r\n"), |
| 20101 | }; |
| 20102 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20103 | MockRead data_reads[] = { |
| 20104 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20105 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20106 | MockRead(SYNCHRONOUS, "1"), |
| 20107 | }; |
| 20108 | |
| 20109 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20110 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20111 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20112 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 20113 | session_deps_.enable_early_data = true; |
| 20114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20115 | |
| 20116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20117 | |
| 20118 | TestCompletionCallback callback; |
| 20119 | auto trans = |
| 20120 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20121 | |
| 20122 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20124 | |
| 20125 | rv = callback.WaitForResult(); |
| 20126 | EXPECT_THAT(rv, IsOk()); |
| 20127 | |
| 20128 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20129 | ASSERT_TRUE(response); |
| 20130 | ASSERT_TRUE(response->headers); |
| 20131 | EXPECT_EQ(200, response->headers->response_code()); |
| 20132 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20133 | |
| 20134 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20135 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20136 | |
| 20137 | trans.reset(); |
| 20138 | |
| 20139 | session->CloseAllConnections(); |
| 20140 | } |
| 20141 | |
| 20142 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 20143 | HttpRequestInfo request; |
| 20144 | request.method = "POST"; |
| 20145 | request.url = GURL("https://www.example.org/"); |
| 20146 | request.traffic_annotation = |
| 20147 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20148 | |
| 20149 | MockWrite data_writes[] = { |
| 20150 | MockWrite(ASYNC, |
| 20151 | "POST / HTTP/1.1\r\n" |
| 20152 | "Host: www.example.org\r\n" |
| 20153 | "Connection: keep-alive\r\n" |
| 20154 | "Content-Length: 0\r\n\r\n"), |
| 20155 | }; |
| 20156 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20157 | MockRead data_reads[] = { |
| 20158 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20159 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20160 | MockRead(SYNCHRONOUS, "1"), |
| 20161 | }; |
| 20162 | |
| 20163 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20164 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20165 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20166 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 20167 | session_deps_.enable_early_data = true; |
| 20168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20169 | |
| 20170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20171 | |
| 20172 | TestCompletionCallback callback; |
| 20173 | auto trans = |
| 20174 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20175 | |
| 20176 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20178 | |
| 20179 | rv = callback.WaitForResult(); |
| 20180 | EXPECT_THAT(rv, IsOk()); |
| 20181 | |
| 20182 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20183 | ASSERT_TRUE(response); |
| 20184 | ASSERT_TRUE(response->headers); |
| 20185 | EXPECT_EQ(200, response->headers->response_code()); |
| 20186 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20187 | |
| 20188 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20189 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20190 | |
| 20191 | trans.reset(); |
| 20192 | |
| 20193 | session->CloseAllConnections(); |
| 20194 | } |
| 20195 | |
David Benjamin | fb97693 | 2019-05-15 13:39:15 | [diff] [blame] | 20196 | // 0-RTT rejects are handled at HttpNetworkTransaction. |
| 20197 | TEST_F(HttpNetworkTransactionTest, ZeroRTTReject) { |
| 20198 | enum class RejectType { |
| 20199 | kRead, |
| 20200 | kWrite, |
| 20201 | kConfirm, |
| 20202 | }; |
| 20203 | |
| 20204 | for (RejectType type : |
| 20205 | {RejectType::kRead, RejectType::kWrite, RejectType::kConfirm}) { |
| 20206 | SCOPED_TRACE(static_cast<int>(type)); |
| 20207 | for (Error reject_error : |
| 20208 | {ERR_EARLY_DATA_REJECTED, ERR_WRONG_VERSION_ON_EARLY_DATA}) { |
| 20209 | SCOPED_TRACE(reject_error); |
| 20210 | session_deps_.socket_factory = |
| 20211 | std::make_unique<MockClientSocketFactory>(); |
| 20212 | |
| 20213 | HttpRequestInfo request; |
| 20214 | request.method = type == RejectType::kConfirm ? "POST" : "GET"; |
| 20215 | request.url = GURL("https://www.example.org/"); |
| 20216 | request.traffic_annotation = |
| 20217 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20218 | |
| 20219 | // The first request fails. |
| 20220 | std::vector<MockWrite> data1_writes; |
| 20221 | std::vector<MockRead> data1_reads; |
| 20222 | SSLSocketDataProvider ssl1(SYNCHRONOUS, OK); |
| 20223 | switch (type) { |
| 20224 | case RejectType::kRead: |
| 20225 | data1_writes.emplace_back( |
| 20226 | "GET / HTTP/1.1\r\n" |
| 20227 | "Host: www.example.org\r\n" |
| 20228 | "Connection: keep-alive\r\n\r\n"); |
| 20229 | data1_reads.emplace_back(ASYNC, reject_error); |
| 20230 | // Cause ConfirmHandshake to hang (it should not be called). |
| 20231 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 20232 | break; |
| 20233 | case RejectType::kWrite: |
| 20234 | data1_writes.emplace_back(ASYNC, reject_error); |
| 20235 | // Cause ConfirmHandshake to hang (it should not be called). |
| 20236 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 20237 | break; |
| 20238 | case RejectType::kConfirm: |
| 20239 | // The request never gets far enough to read or write. |
| 20240 | ssl1.confirm = MockConfirm(ASYNC, reject_error); |
| 20241 | break; |
| 20242 | } |
| 20243 | |
| 20244 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 20245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20246 | session_deps_.enable_early_data = true; |
| 20247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20248 | |
| 20249 | // The retry succeeds. |
| 20250 | // |
| 20251 | // TODO(https://crbug.com/950705): If |reject_error| is |
| 20252 | // ERR_EARLY_DATA_REJECTED, the retry should happen over the same socket. |
| 20253 | MockWrite data2_writes[] = { |
| 20254 | request.method == "POST" |
| 20255 | ? MockWrite("POST / HTTP/1.1\r\n" |
| 20256 | "Host: www.example.org\r\n" |
| 20257 | "Connection: keep-alive\r\n" |
| 20258 | "Content-Length: 0\r\n\r\n") |
| 20259 | : MockWrite("GET / HTTP/1.1\r\n" |
| 20260 | "Host: www.example.org\r\n" |
| 20261 | "Connection: keep-alive\r\n\r\n"), |
| 20262 | }; |
| 20263 | |
| 20264 | MockRead data2_reads[] = { |
| 20265 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20266 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20267 | MockRead(SYNCHRONOUS, "1"), |
| 20268 | }; |
| 20269 | |
| 20270 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 20271 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20272 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 20273 | ssl2.confirm = MockConfirm(ASYNC, OK); |
| 20274 | session_deps_.enable_early_data = true; |
| 20275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20276 | |
| 20277 | std::unique_ptr<HttpNetworkSession> session( |
| 20278 | CreateSession(&session_deps_)); |
| 20279 | |
| 20280 | TestCompletionCallback callback; |
| 20281 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 20282 | session.get()); |
| 20283 | |
| 20284 | EXPECT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20285 | NetLogWithSource())), |
| 20286 | IsOk()); |
| 20287 | |
| 20288 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20289 | ASSERT_TRUE(response); |
| 20290 | ASSERT_TRUE(response->headers); |
| 20291 | EXPECT_EQ(200, response->headers->response_code()); |
| 20292 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20293 | } |
| 20294 | } |
| 20295 | } |
| 20296 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20297 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 20298 | HttpRequestInfo request; |
| 20299 | request.method = "POST"; |
| 20300 | request.url = GURL("https://www.example.org/"); |
| 20301 | request.traffic_annotation = |
| 20302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20303 | |
| 20304 | MockWrite data_writes[] = { |
| 20305 | MockWrite("POST / HTTP/1.1\r\n" |
| 20306 | "Host: www.example.org\r\n" |
| 20307 | "Connection: keep-alive\r\n" |
| 20308 | "Content-Length: 0\r\n\r\n"), |
| 20309 | }; |
| 20310 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20311 | MockRead data_reads[] = { |
| 20312 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20313 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20314 | MockRead(SYNCHRONOUS, "1"), |
| 20315 | }; |
| 20316 | |
| 20317 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20319 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20320 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 20321 | session_deps_.enable_early_data = true; |
| 20322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20323 | |
| 20324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20325 | |
| 20326 | TestCompletionCallback callback; |
| 20327 | auto trans = |
| 20328 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20329 | |
| 20330 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20332 | |
| 20333 | rv = callback.WaitForResult(); |
| 20334 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20335 | |
| 20336 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20337 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20338 | |
| 20339 | trans.reset(); |
| 20340 | |
| 20341 | session->CloseAllConnections(); |
| 20342 | } |
| 20343 | |
| 20344 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 20345 | HttpRequestInfo request; |
| 20346 | request.method = "POST"; |
| 20347 | request.url = GURL("https://www.example.org/"); |
| 20348 | request.traffic_annotation = |
| 20349 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20350 | |
| 20351 | MockWrite data_writes[] = { |
| 20352 | MockWrite("POST / HTTP/1.1\r\n" |
| 20353 | "Host: www.example.org\r\n" |
| 20354 | "Connection: keep-alive\r\n" |
| 20355 | "Content-Length: 0\r\n\r\n"), |
| 20356 | }; |
| 20357 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20358 | MockRead data_reads[] = { |
| 20359 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20360 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20361 | MockRead(SYNCHRONOUS, "1"), |
| 20362 | }; |
| 20363 | |
| 20364 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20365 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20366 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20367 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 20368 | session_deps_.enable_early_data = true; |
| 20369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20370 | |
| 20371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20372 | |
| 20373 | TestCompletionCallback callback; |
| 20374 | auto trans = |
| 20375 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20376 | |
| 20377 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20378 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20379 | |
| 20380 | rv = callback.WaitForResult(); |
| 20381 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20382 | |
| 20383 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20384 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20385 | |
| 20386 | trans.reset(); |
| 20387 | |
| 20388 | session->CloseAllConnections(); |
| 20389 | } |
| 20390 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20391 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20392 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 20393 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 20394 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20395 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20396 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20397 | |
| 20398 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20399 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20400 | |
| 20401 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20402 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20403 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20404 | ASSERT_TRUE(identity_proxy); |
| 20405 | |
| 20406 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20407 | cert_request_info_origin->host_and_port = |
| 20408 | HostPortPair("www.example.org", 443); |
| 20409 | |
| 20410 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20411 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20412 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20413 | ASSERT_TRUE(identity_origin); |
| 20414 | |
| 20415 | HttpRequestInfo request; |
| 20416 | request.method = "GET"; |
| 20417 | request.url = GURL("https://www.example.org/"); |
| 20418 | request.traffic_annotation = |
| 20419 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20420 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20421 | // First, the client connects to the proxy, which requests a client |
| 20422 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20423 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20424 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20425 | ssl_proxy1.expected_send_client_cert = false; |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20426 | StaticSocketDataProvider data1; |
| 20427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20429 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20430 | // The client responds with a certificate on a new connection. The handshake |
| 20431 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20432 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20433 | ssl_proxy2.expected_send_client_cert = true; |
| 20434 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20435 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20436 | std::vector<MockWrite> mock_writes2; |
| 20437 | std::vector<MockRead> mock_reads2; |
| 20438 | mock_writes2.emplace_back( |
| 20439 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20440 | "Host: www.example.org:443\r\n" |
| 20441 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20442 | mock_reads2.emplace_back( |
| 20443 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20444 | "Content-Length: 0\r\n" |
| 20445 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20446 | // The client retries with credentials. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20447 | mock_writes2.emplace_back( |
| 20448 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20449 | "Host: www.example.org:443\r\n" |
| 20450 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20451 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20452 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20453 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20454 | // The origin requests client certificates. |
| 20455 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20456 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20457 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20461 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20462 | // The client responds to the origin client certificate request on a new |
| 20463 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20464 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20465 | ssl_proxy3.expected_send_client_cert = true; |
| 20466 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20467 | std::vector<MockWrite> mock_writes3; |
| 20468 | std::vector<MockRead> mock_reads3; |
| 20469 | mock_writes3.emplace_back( |
| 20470 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20471 | "Host: www.example.org:443\r\n" |
| 20472 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20473 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20474 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20475 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20476 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 20477 | ssl_origin3.expected_send_client_cert = true; |
| 20478 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20479 | // The client sends the origin HTTP request, which results in another HTTP |
| 20480 | // auth request. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20481 | mock_writes3.emplace_back( |
| 20482 | "GET / HTTP/1.1\r\n" |
| 20483 | "Host: www.example.org\r\n" |
| 20484 | "Connection: keep-alive\r\n\r\n"); |
| 20485 | mock_reads3.emplace_back( |
| 20486 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20487 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20488 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20489 | // The client retries with credentials, and the request finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20490 | mock_writes3.emplace_back( |
| 20491 | "GET / HTTP/1.1\r\n" |
| 20492 | "Host: www.example.org\r\n" |
| 20493 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20494 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20495 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20496 | mock_reads3.emplace_back( |
| 20497 | "HTTP/1.1 200 OK\r\n" |
| 20498 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20499 | // The client makes another request. This should reuse the socket with all |
| 20500 | // credentials cached. |
| 20501 | mock_writes3.emplace_back( |
| 20502 | "GET / HTTP/1.1\r\n" |
| 20503 | "Host: www.example.org\r\n" |
| 20504 | "Connection: keep-alive\r\n" |
| 20505 | // Authenticate as user:pass. |
| 20506 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20507 | mock_reads3.emplace_back( |
| 20508 | "HTTP/1.1 200 OK\r\n" |
| 20509 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20510 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20511 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20512 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20514 | |
| 20515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20516 | |
| 20517 | // Start the request. |
| 20518 | TestCompletionCallback callback; |
| 20519 | auto trans = |
| 20520 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20521 | int rv = callback.GetResult( |
| 20522 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20523 | |
| 20524 | // Handle the proxy client certificate challenge. |
| 20525 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20526 | SSLCertRequestInfo* cert_request_info = |
| 20527 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20528 | ASSERT_TRUE(cert_request_info); |
| 20529 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20530 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20531 | cert_request_info_proxy->host_and_port); |
| 20532 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20533 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20534 | callback.callback())); |
| 20535 | |
| 20536 | // Handle the proxy HTTP auth challenge. |
| 20537 | ASSERT_THAT(rv, IsOk()); |
| 20538 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20539 | EXPECT_TRUE( |
| 20540 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20541 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20542 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20543 | callback.callback())); |
| 20544 | |
| 20545 | // Handle the origin client certificate challenge. |
| 20546 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20547 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20548 | ASSERT_TRUE(cert_request_info); |
| 20549 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20550 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20551 | cert_request_info_origin->host_and_port); |
| 20552 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20553 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20554 | callback.callback())); |
| 20555 | |
| 20556 | // Handle the origin HTTP auth challenge. |
| 20557 | ASSERT_THAT(rv, IsOk()); |
| 20558 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20559 | EXPECT_TRUE( |
| 20560 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20561 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20562 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20563 | callback.callback())); |
| 20564 | |
| 20565 | // The request completes. |
| 20566 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20567 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20568 | |
| 20569 | // Make a second request. This time all credentials are cached. |
| 20570 | trans = |
| 20571 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20572 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20573 | NetLogWithSource())), |
| 20574 | IsOk()); |
| 20575 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20576 | } |
| 20577 | |
| 20578 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20579 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 20580 | // test for https://crbug.com/946406. |
| 20581 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 20582 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20583 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20584 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20585 | |
| 20586 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20587 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20588 | |
| 20589 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20590 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20591 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20592 | ASSERT_TRUE(identity_proxy); |
| 20593 | |
| 20594 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20595 | cert_request_info_origin->host_and_port = |
| 20596 | HostPortPair("www.example.org", 443); |
| 20597 | |
| 20598 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20599 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20600 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20601 | ASSERT_TRUE(identity_origin); |
| 20602 | |
| 20603 | HttpRequestInfo request; |
| 20604 | request.method = "GET"; |
| 20605 | request.url = GURL("https://www.example.org/"); |
| 20606 | request.traffic_annotation = |
| 20607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20608 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20609 | // First, the client connects to the proxy, which requests a client |
| 20610 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20611 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20612 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20613 | ssl_proxy1.expected_send_client_cert = false; |
| 20614 | StaticSocketDataProvider data1; |
| 20615 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20617 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20618 | // The client responds with a certificate on a new connection. The handshake |
| 20619 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20620 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20621 | ssl_proxy2.expected_send_client_cert = true; |
| 20622 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20623 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20624 | std::vector<MockWrite> mock_writes2; |
| 20625 | std::vector<MockRead> mock_reads2; |
| 20626 | mock_writes2.emplace_back( |
| 20627 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20628 | "Host: www.example.org:443\r\n" |
| 20629 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20630 | mock_reads2.emplace_back( |
| 20631 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20632 | "Content-Length: 0\r\n" |
| 20633 | "Proxy-Connection: close\r\n" |
| 20634 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20635 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20636 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20637 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20638 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20639 | // The client retries with credentials on a new connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20640 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20641 | ssl_proxy3.expected_send_client_cert = true; |
| 20642 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 20643 | std::vector<MockWrite> mock_writes3; |
| 20644 | std::vector<MockRead> mock_reads3; |
| 20645 | mock_writes3.emplace_back( |
| 20646 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20647 | "Host: www.example.org:443\r\n" |
| 20648 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20649 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20650 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20651 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20652 | // The origin requests client certificates. |
| 20653 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20654 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 20655 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20656 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20659 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20660 | // The client responds to the origin client certificate request on a new |
| 20661 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20662 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 20663 | ssl_proxy4.expected_send_client_cert = true; |
| 20664 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 20665 | std::vector<MockWrite> mock_writes4; |
| 20666 | std::vector<MockRead> mock_reads4; |
| 20667 | mock_writes4.emplace_back( |
| 20668 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20669 | "Host: www.example.org:443\r\n" |
| 20670 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20671 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20672 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20673 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20674 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 20675 | ssl_origin4.expected_send_client_cert = true; |
| 20676 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20677 | // The client sends the origin HTTP request, which results in another HTTP |
| 20678 | // auth request and closed connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20679 | mock_writes4.emplace_back( |
| 20680 | "GET / HTTP/1.1\r\n" |
| 20681 | "Host: www.example.org\r\n" |
| 20682 | "Connection: keep-alive\r\n\r\n"); |
| 20683 | mock_reads4.emplace_back( |
| 20684 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20685 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20686 | "Connection: close\r\n" |
| 20687 | "Content-Length: 0\r\n\r\n"); |
| 20688 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 20689 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 20691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20692 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20693 | // The client retries with credentials on a new connection, and the request |
| 20694 | // finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20695 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 20696 | ssl_proxy5.expected_send_client_cert = true; |
| 20697 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 20698 | std::vector<MockWrite> mock_writes5; |
| 20699 | std::vector<MockRead> mock_reads5; |
| 20700 | mock_writes5.emplace_back( |
| 20701 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20702 | "Host: www.example.org:443\r\n" |
| 20703 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20704 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20705 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20706 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20707 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 20708 | ssl_origin5.expected_send_client_cert = true; |
| 20709 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 20710 | mock_writes5.emplace_back( |
| 20711 | "GET / HTTP/1.1\r\n" |
| 20712 | "Host: www.example.org\r\n" |
| 20713 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20714 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20715 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20716 | mock_reads5.emplace_back( |
| 20717 | "HTTP/1.1 200 OK\r\n" |
| 20718 | "Connection: close\r\n" |
| 20719 | "Content-Length: 0\r\n\r\n"); |
| 20720 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 20721 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20722 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 20723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20724 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20725 | // The client makes a second request. This needs yet another connection, but |
| 20726 | // all credentials are cached. |
| 20727 | SSLSocketDataProvider ssl_proxy6(ASYNC, OK); |
| 20728 | ssl_proxy6.expected_send_client_cert = true; |
| 20729 | ssl_proxy6.expected_client_cert = identity_proxy->certificate(); |
| 20730 | std::vector<MockWrite> mock_writes6; |
| 20731 | std::vector<MockRead> mock_reads6; |
| 20732 | mock_writes6.emplace_back( |
| 20733 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20734 | "Host: www.example.org:443\r\n" |
| 20735 | "Proxy-Connection: keep-alive\r\n" |
| 20736 | // Authenticate as proxyuser:proxypass. |
| 20737 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20738 | mock_reads6.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20739 | SSLSocketDataProvider ssl_origin6(ASYNC, OK); |
| 20740 | ssl_origin6.expected_send_client_cert = true; |
| 20741 | ssl_origin6.expected_client_cert = identity_origin->certificate(); |
| 20742 | mock_writes6.emplace_back( |
| 20743 | "GET / HTTP/1.1\r\n" |
| 20744 | "Host: www.example.org\r\n" |
| 20745 | "Connection: keep-alive\r\n" |
| 20746 | // Authenticate as user:pass. |
| 20747 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20748 | mock_reads6.emplace_back( |
| 20749 | "HTTP/1.1 200 OK\r\n" |
| 20750 | "Connection: close\r\n" |
| 20751 | "Content-Length: 0\r\n\r\n"); |
| 20752 | StaticSocketDataProvider data6(mock_reads6, mock_writes6); |
| 20753 | session_deps_.socket_factory->AddSocketDataProvider(&data6); |
| 20754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy6); |
| 20755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin6); |
| 20756 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20758 | |
| 20759 | // Start the request. |
| 20760 | TestCompletionCallback callback; |
| 20761 | auto trans = |
| 20762 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20763 | int rv = callback.GetResult( |
| 20764 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20765 | |
| 20766 | // Handle the proxy client certificate challenge. |
| 20767 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20768 | SSLCertRequestInfo* cert_request_info = |
| 20769 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20770 | ASSERT_TRUE(cert_request_info); |
| 20771 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20772 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20773 | cert_request_info_proxy->host_and_port); |
| 20774 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20775 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20776 | callback.callback())); |
| 20777 | |
| 20778 | // Handle the proxy HTTP auth challenge. |
| 20779 | ASSERT_THAT(rv, IsOk()); |
| 20780 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20781 | EXPECT_TRUE( |
| 20782 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20783 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20784 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20785 | callback.callback())); |
| 20786 | |
| 20787 | // Handle the origin client certificate challenge. |
| 20788 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20789 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20790 | ASSERT_TRUE(cert_request_info); |
| 20791 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20792 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20793 | cert_request_info_origin->host_and_port); |
| 20794 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20795 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20796 | callback.callback())); |
| 20797 | |
| 20798 | // Handle the origin HTTP auth challenge. |
| 20799 | ASSERT_THAT(rv, IsOk()); |
| 20800 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20801 | EXPECT_TRUE( |
| 20802 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20803 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20804 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20805 | callback.callback())); |
| 20806 | |
| 20807 | // The request completes. |
| 20808 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20809 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20810 | |
| 20811 | // Make a second request. This time all credentials are cached. |
| 20812 | trans = |
| 20813 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20814 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20815 | NetLogWithSource())), |
| 20816 | IsOk()); |
| 20817 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20818 | } |
| 20819 | |
| 20820 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 20821 | // certificates. This is a regression test for https://crbug.com/946406. |
| 20822 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 20823 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20824 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20825 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20826 | |
| 20827 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20828 | cert_request_info_origin->host_and_port = |
| 20829 | HostPortPair("www.example.org", 443); |
| 20830 | |
| 20831 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20832 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20833 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20834 | ASSERT_TRUE(identity_origin); |
| 20835 | |
| 20836 | HttpRequestInfo request; |
| 20837 | request.method = "GET"; |
| 20838 | request.url = GURL("https://www.example.org/"); |
| 20839 | request.traffic_annotation = |
| 20840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20841 | |
| 20842 | // The client connects to the proxy. The handshake succeeds. |
| 20843 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 20844 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20845 | std::vector<MockWrite> mock_writes1; |
| 20846 | std::vector<MockRead> mock_reads1; |
| 20847 | mock_writes1.emplace_back( |
| 20848 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20849 | "Host: www.example.org:443\r\n" |
| 20850 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20851 | mock_reads1.emplace_back( |
| 20852 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20853 | "Content-Length: 0\r\n" |
| 20854 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20855 | // The client retries with credentials, and the request finally succeeds. |
| 20856 | mock_writes1.emplace_back( |
| 20857 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20858 | "Host: www.example.org:443\r\n" |
| 20859 | "Proxy-Connection: keep-alive\r\n" |
| 20860 | // Authenticate as proxyuser:proxypass. |
| 20861 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20862 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20863 | // The origin requests client certificates. |
| 20864 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20865 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 20866 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 20867 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 20869 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 20870 | |
| 20871 | // The client responds to the origin client certificate request on a new |
| 20872 | // connection. |
| 20873 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20874 | std::vector<MockWrite> mock_writes2; |
| 20875 | std::vector<MockRead> mock_reads2; |
| 20876 | mock_writes2.emplace_back( |
| 20877 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20878 | "Host: www.example.org:443\r\n" |
| 20879 | "Proxy-Connection: keep-alive\r\n" |
| 20880 | // Authenticate as proxyuser:proxypass. |
| 20881 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20882 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20883 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 20884 | ssl_origin2.expected_send_client_cert = true; |
| 20885 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 20886 | // The client sends the origin HTTP request, which succeeds. |
| 20887 | mock_writes2.emplace_back( |
| 20888 | "GET / HTTP/1.1\r\n" |
| 20889 | "Host: www.example.org\r\n" |
| 20890 | "Connection: keep-alive\r\n\r\n"); |
| 20891 | mock_reads2.emplace_back( |
| 20892 | "HTTP/1.1 200 OK\r\n" |
| 20893 | "Content-Length: 0\r\n\r\n"); |
| 20894 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20895 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 20898 | |
| 20899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20900 | |
| 20901 | // Start the request. |
| 20902 | TestCompletionCallback callback; |
| 20903 | auto trans = |
| 20904 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20905 | int rv = callback.GetResult( |
| 20906 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20907 | |
| 20908 | // Handle the proxy HTTP auth challenge. |
| 20909 | ASSERT_THAT(rv, IsOk()); |
| 20910 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20911 | EXPECT_TRUE( |
| 20912 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20913 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20914 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20915 | callback.callback())); |
| 20916 | |
| 20917 | // Handle the origin client certificate challenge. |
| 20918 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20919 | SSLCertRequestInfo* cert_request_info = |
| 20920 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20921 | ASSERT_TRUE(cert_request_info); |
| 20922 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20923 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20924 | cert_request_info_origin->host_and_port); |
| 20925 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20926 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20927 | callback.callback())); |
| 20928 | |
| 20929 | // The request completes. |
| 20930 | ASSERT_THAT(rv, IsOk()); |
| 20931 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20932 | } |
| 20933 | |
David Benjamin | 6e673a8 | 2019-04-30 22:52:58 | [diff] [blame] | 20934 | // Test that socket reuse works with client certificates. |
| 20935 | TEST_F(HttpNetworkTransactionTest, ClientCertSocketReuse) { |
| 20936 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20937 | cert_request_info->host_and_port = HostPortPair("www.example.org", 443); |
| 20938 | |
| 20939 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 20940 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20941 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20942 | ASSERT_TRUE(identity); |
| 20943 | |
| 20944 | HttpRequestInfo request1; |
| 20945 | request1.method = "GET"; |
| 20946 | request1.url = GURL("https://www.example.org/a"); |
| 20947 | request1.traffic_annotation = |
| 20948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20949 | |
| 20950 | HttpRequestInfo request2; |
| 20951 | request2.method = "GET"; |
| 20952 | request2.url = GURL("https://www.example.org/b"); |
| 20953 | request2.traffic_annotation = |
| 20954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20955 | |
| 20956 | // The first connection results in a client certificate request. |
| 20957 | StaticSocketDataProvider data1; |
| 20958 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20959 | SSLSocketDataProvider ssl1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20960 | ssl1.cert_request_info = cert_request_info.get(); |
| 20961 | ssl1.expected_send_client_cert = false; |
| 20962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20963 | |
| 20964 | // The second connection succeeds and is usable for both requests. |
| 20965 | MockWrite mock_writes[] = { |
| 20966 | MockWrite("GET /a HTTP/1.1\r\n" |
| 20967 | "Host: www.example.org\r\n" |
| 20968 | "Connection: keep-alive\r\n\r\n"), |
| 20969 | MockWrite("GET /b HTTP/1.1\r\n" |
| 20970 | "Host: www.example.org\r\n" |
| 20971 | "Connection: keep-alive\r\n\r\n"), |
| 20972 | }; |
| 20973 | MockRead mock_reads[] = { |
| 20974 | MockRead("HTTP/1.1 200 OK\r\n" |
| 20975 | "Content-Length: 0\r\n\r\n"), |
| 20976 | MockRead("HTTP/1.1 200 OK\r\n" |
| 20977 | "Content-Length: 0\r\n\r\n"), |
| 20978 | }; |
| 20979 | StaticSocketDataProvider data2(mock_reads, mock_writes); |
| 20980 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20981 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 20982 | ssl2.expected_send_client_cert = true; |
| 20983 | ssl2.expected_client_cert = identity->certificate(); |
| 20984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20985 | |
| 20986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20987 | |
| 20988 | // Start the first request. It succeeds after providing client certificates. |
| 20989 | TestCompletionCallback callback; |
| 20990 | auto trans = |
| 20991 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20992 | ASSERT_THAT(callback.GetResult(trans->Start(&request1, callback.callback(), |
| 20993 | NetLogWithSource())), |
| 20994 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20995 | |
| 20996 | SSLCertRequestInfo* info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20997 | ASSERT_TRUE(info); |
| 20998 | EXPECT_FALSE(info->is_proxy); |
| 20999 | EXPECT_EQ(info->host_and_port, cert_request_info->host_and_port); |
| 21000 | |
| 21001 | ASSERT_THAT(callback.GetResult(trans->RestartWithCertificate( |
| 21002 | identity->certificate(), identity->ssl_private_key(), |
| 21003 | callback.callback())), |
| 21004 | IsOk()); |
| 21005 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21006 | |
| 21007 | // Make the second request. It completes without requesting client |
| 21008 | // certificates. |
| 21009 | trans = |
| 21010 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21011 | ASSERT_THAT(callback.GetResult(trans->Start(&request2, callback.callback(), |
| 21012 | NetLogWithSource())), |
| 21013 | IsOk()); |
| 21014 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21015 | } |
| 21016 | |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21017 | // Test for kPartitionConnectionsByNetworkIsolationKey. Runs 3 requests in |
| 21018 | // sequence with two different NetworkIsolationKeys, the first and last have the |
| 21019 | // same key, the second a different one. Checks that the requests are |
| 21020 | // partitioned across sockets as expected. |
| 21021 | TEST_F(HttpNetworkTransactionTest, NetworkIsolation) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21022 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21023 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21024 | NetworkIsolationKey network_isolation_key1(kOrigin1, kOrigin1); |
| 21025 | NetworkIsolationKey network_isolation_key2(kOrigin2, kOrigin2); |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21026 | |
| 21027 | for (bool partition_connections : {false, true}) { |
| 21028 | SCOPED_TRACE(partition_connections); |
| 21029 | |
| 21030 | base::test::ScopedFeatureList feature_list; |
| 21031 | if (partition_connections) { |
| 21032 | feature_list.InitAndEnableFeature( |
| 21033 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21034 | } else { |
| 21035 | feature_list.InitAndDisableFeature( |
| 21036 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21037 | } |
| 21038 | |
| 21039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21040 | |
| 21041 | // Reads and writes for the unpartitioned case, where only one socket is |
| 21042 | // used. |
| 21043 | |
| 21044 | const MockWrite kUnpartitionedWrites[] = { |
| 21045 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21046 | "Host: foo.test\r\n" |
| 21047 | "Connection: keep-alive\r\n\r\n"), |
| 21048 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21049 | "Host: foo.test\r\n" |
| 21050 | "Connection: keep-alive\r\n\r\n"), |
| 21051 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21052 | "Host: foo.test\r\n" |
| 21053 | "Connection: keep-alive\r\n\r\n"), |
| 21054 | }; |
| 21055 | |
| 21056 | const MockRead kUnpartitionedReads[] = { |
| 21057 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21058 | "Connection: keep-alive\r\n" |
| 21059 | "Content-Length: 1\r\n\r\n" |
| 21060 | "1"), |
| 21061 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21062 | "Connection: keep-alive\r\n" |
| 21063 | "Content-Length: 1\r\n\r\n" |
| 21064 | "2"), |
| 21065 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21066 | "Connection: keep-alive\r\n" |
| 21067 | "Content-Length: 1\r\n\r\n" |
| 21068 | "3"), |
| 21069 | }; |
| 21070 | |
| 21071 | StaticSocketDataProvider unpartitioned_data(kUnpartitionedReads, |
| 21072 | kUnpartitionedWrites); |
| 21073 | |
| 21074 | // Reads and writes for the partitioned case, where two sockets are used. |
| 21075 | |
| 21076 | const MockWrite kPartitionedWrites1[] = { |
| 21077 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21078 | "Host: foo.test\r\n" |
| 21079 | "Connection: keep-alive\r\n\r\n"), |
| 21080 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21081 | "Host: foo.test\r\n" |
| 21082 | "Connection: keep-alive\r\n\r\n"), |
| 21083 | }; |
| 21084 | |
| 21085 | const MockRead kPartitionedReads1[] = { |
| 21086 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21087 | "Connection: keep-alive\r\n" |
| 21088 | "Content-Length: 1\r\n\r\n" |
| 21089 | "1"), |
| 21090 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21091 | "Connection: keep-alive\r\n" |
| 21092 | "Content-Length: 1\r\n\r\n" |
| 21093 | "3"), |
| 21094 | }; |
| 21095 | |
| 21096 | const MockWrite kPartitionedWrites2[] = { |
| 21097 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21098 | "Host: foo.test\r\n" |
| 21099 | "Connection: keep-alive\r\n\r\n"), |
| 21100 | }; |
| 21101 | |
| 21102 | const MockRead kPartitionedReads2[] = { |
| 21103 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21104 | "Connection: keep-alive\r\n" |
| 21105 | "Content-Length: 1\r\n\r\n" |
| 21106 | "2"), |
| 21107 | }; |
| 21108 | |
| 21109 | StaticSocketDataProvider partitioned_data1(kPartitionedReads1, |
| 21110 | kPartitionedWrites1); |
| 21111 | StaticSocketDataProvider partitioned_data2(kPartitionedReads2, |
| 21112 | kPartitionedWrites2); |
| 21113 | |
| 21114 | if (partition_connections) { |
| 21115 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 21116 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 21117 | } else { |
| 21118 | session_deps_.socket_factory->AddSocketDataProvider(&unpartitioned_data); |
| 21119 | } |
| 21120 | |
| 21121 | TestCompletionCallback callback; |
| 21122 | HttpRequestInfo request1; |
| 21123 | request1.method = "GET"; |
| 21124 | request1.url = GURL("http://foo.test/1"); |
| 21125 | request1.traffic_annotation = |
| 21126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21127 | request1.network_isolation_key = network_isolation_key1; |
| 21128 | auto trans1 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21129 | session.get()); |
| 21130 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21131 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21132 | std::string response_data1; |
| 21133 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21134 | EXPECT_EQ("1", response_data1); |
| 21135 | trans1.reset(); |
| 21136 | |
| 21137 | HttpRequestInfo request2; |
| 21138 | request2.method = "GET"; |
| 21139 | request2.url = GURL("http://foo.test/2"); |
| 21140 | request2.traffic_annotation = |
| 21141 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21142 | request2.network_isolation_key = network_isolation_key2; |
| 21143 | auto trans2 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21144 | session.get()); |
| 21145 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21146 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21147 | std::string response_data2; |
| 21148 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21149 | EXPECT_EQ("2", response_data2); |
| 21150 | trans2.reset(); |
| 21151 | |
| 21152 | HttpRequestInfo request3; |
| 21153 | request3.method = "GET"; |
| 21154 | request3.url = GURL("http://foo.test/3"); |
| 21155 | request3.traffic_annotation = |
| 21156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21157 | request3.network_isolation_key = network_isolation_key1; |
| 21158 | auto trans3 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21159 | session.get()); |
| 21160 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21161 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21162 | std::string response_data3; |
| 21163 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21164 | EXPECT_EQ("3", response_data3); |
| 21165 | trans3.reset(); |
| 21166 | } |
| 21167 | } |
| 21168 | |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 21169 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationH2) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21170 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21171 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21172 | NetworkIsolationKey network_isolation_key1(kOrigin1, kOrigin1); |
| 21173 | NetworkIsolationKey network_isolation_key2(kOrigin2, kOrigin2); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 21174 | |
| 21175 | // Whether to use an H2 proxy. When false, uses HTTPS H2 requests without a |
| 21176 | // proxy, when true, uses HTTP requests over an H2 proxy. It's unnecessary to |
| 21177 | // test tunneled HTTPS over an H2 proxy, since that path sets up H2 sessions |
| 21178 | // the same way as the HTTP over H2 proxy case. |
| 21179 | for (bool use_proxy : {false, true}) { |
| 21180 | SCOPED_TRACE(use_proxy); |
| 21181 | if (use_proxy) { |
| 21182 | session_deps_.proxy_resolution_service = |
| 21183 | ProxyResolutionService::CreateFixedFromPacResult( |
| 21184 | "HTTPS proxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21185 | } else { |
| 21186 | session_deps_.proxy_resolution_service = |
| 21187 | ProxyResolutionService::CreateDirect(); |
| 21188 | } |
| 21189 | const char* url1 = nullptr; |
| 21190 | const char* url2 = nullptr; |
| 21191 | const char* url3 = nullptr; |
| 21192 | if (use_proxy) { |
| 21193 | url1 = "http://foo.test/1"; |
| 21194 | url2 = "http://foo.test/2"; |
| 21195 | url3 = "http://foo.test/3"; |
| 21196 | } else { |
| 21197 | url1 = "https://foo.test/1"; |
| 21198 | url2 = "https://foo.test/2"; |
| 21199 | url3 = "https://foo.test/3"; |
| 21200 | } |
| 21201 | |
| 21202 | for (bool partition_connections : {false, true}) { |
| 21203 | SCOPED_TRACE(partition_connections); |
| 21204 | |
| 21205 | base::test::ScopedFeatureList feature_list; |
| 21206 | if (partition_connections) { |
| 21207 | feature_list.InitAndEnableFeature( |
| 21208 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21209 | } else { |
| 21210 | feature_list.InitAndDisableFeature( |
| 21211 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21212 | } |
| 21213 | |
| 21214 | std::unique_ptr<HttpNetworkSession> session( |
| 21215 | CreateSession(&session_deps_)); |
| 21216 | |
| 21217 | // Reads and writes for the unpartitioned case, where only one socket is |
| 21218 | // used. |
| 21219 | |
| 21220 | SpdyTestUtil spdy_util; |
| 21221 | spdy::SpdySerializedFrame unpartitioned_req1( |
| 21222 | spdy_util.ConstructSpdyGet(url1, 1, LOWEST)); |
| 21223 | spdy::SpdySerializedFrame unpartitioned_response1( |
| 21224 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21225 | spdy::SpdySerializedFrame unpartitioned_body1( |
| 21226 | spdy_util.ConstructSpdyDataFrame(1, "1", true)); |
| 21227 | spdy_util.UpdateWithStreamDestruction(1); |
| 21228 | |
| 21229 | spdy::SpdySerializedFrame unpartitioned_req2( |
| 21230 | spdy_util.ConstructSpdyGet(url2, 3, LOWEST)); |
| 21231 | spdy::SpdySerializedFrame unpartitioned_response2( |
| 21232 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 21233 | spdy::SpdySerializedFrame unpartitioned_body2( |
| 21234 | spdy_util.ConstructSpdyDataFrame(3, "2", true)); |
| 21235 | spdy_util.UpdateWithStreamDestruction(3); |
| 21236 | |
| 21237 | spdy::SpdySerializedFrame unpartitioned_req3( |
| 21238 | spdy_util.ConstructSpdyGet(url3, 5, LOWEST)); |
| 21239 | spdy::SpdySerializedFrame unpartitioned_response3( |
| 21240 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 5)); |
| 21241 | spdy::SpdySerializedFrame unpartitioned_body3( |
| 21242 | spdy_util.ConstructSpdyDataFrame(5, "3", true)); |
| 21243 | |
| 21244 | const MockWrite kUnpartitionedWrites[] = { |
| 21245 | CreateMockWrite(unpartitioned_req1, 0), |
| 21246 | CreateMockWrite(unpartitioned_req2, 3), |
| 21247 | CreateMockWrite(unpartitioned_req3, 6), |
| 21248 | }; |
| 21249 | |
| 21250 | const MockRead kUnpartitionedReads[] = { |
| 21251 | CreateMockRead(unpartitioned_response1, 1), |
| 21252 | CreateMockRead(unpartitioned_body1, 2), |
| 21253 | CreateMockRead(unpartitioned_response2, 4), |
| 21254 | CreateMockRead(unpartitioned_body2, 5), |
| 21255 | CreateMockRead(unpartitioned_response3, 7), |
| 21256 | CreateMockRead(unpartitioned_body3, 8), |
| 21257 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), |
| 21258 | }; |
| 21259 | |
| 21260 | SequencedSocketData unpartitioned_data(kUnpartitionedReads, |
| 21261 | kUnpartitionedWrites); |
| 21262 | |
| 21263 | // Reads and writes for the partitioned case, where two sockets are used. |
| 21264 | |
| 21265 | SpdyTestUtil spdy_util2; |
| 21266 | spdy::SpdySerializedFrame partitioned_req1( |
| 21267 | spdy_util2.ConstructSpdyGet(url1, 1, LOWEST)); |
| 21268 | spdy::SpdySerializedFrame partitioned_response1( |
| 21269 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21270 | spdy::SpdySerializedFrame partitioned_body1( |
| 21271 | spdy_util2.ConstructSpdyDataFrame(1, "1", true)); |
| 21272 | spdy_util2.UpdateWithStreamDestruction(1); |
| 21273 | |
| 21274 | spdy::SpdySerializedFrame partitioned_req3( |
| 21275 | spdy_util2.ConstructSpdyGet(url3, 3, LOWEST)); |
| 21276 | spdy::SpdySerializedFrame partitioned_response3( |
| 21277 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 21278 | spdy::SpdySerializedFrame partitioned_body3( |
| 21279 | spdy_util2.ConstructSpdyDataFrame(3, "3", true)); |
| 21280 | |
| 21281 | const MockWrite kPartitionedWrites1[] = { |
| 21282 | CreateMockWrite(partitioned_req1, 0), |
| 21283 | CreateMockWrite(partitioned_req3, 3), |
| 21284 | }; |
| 21285 | |
| 21286 | const MockRead kPartitionedReads1[] = { |
| 21287 | CreateMockRead(partitioned_response1, 1), |
| 21288 | CreateMockRead(partitioned_body1, 2), |
| 21289 | CreateMockRead(partitioned_response3, 4), |
| 21290 | CreateMockRead(partitioned_body3, 5), |
| 21291 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 21292 | }; |
| 21293 | |
| 21294 | SpdyTestUtil spdy_util3; |
| 21295 | spdy::SpdySerializedFrame partitioned_req2( |
| 21296 | spdy_util3.ConstructSpdyGet(url2, 1, LOWEST)); |
| 21297 | spdy::SpdySerializedFrame partitioned_response2( |
| 21298 | spdy_util3.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21299 | spdy::SpdySerializedFrame partitioned_body2( |
| 21300 | spdy_util3.ConstructSpdyDataFrame(1, "2", true)); |
| 21301 | |
| 21302 | const MockWrite kPartitionedWrites2[] = { |
| 21303 | CreateMockWrite(partitioned_req2, 0), |
| 21304 | }; |
| 21305 | |
| 21306 | const MockRead kPartitionedReads2[] = { |
| 21307 | CreateMockRead(partitioned_response2, 1), |
| 21308 | CreateMockRead(partitioned_body2, 2), |
| 21309 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
| 21310 | }; |
| 21311 | |
| 21312 | SequencedSocketData partitioned_data1(kPartitionedReads1, |
| 21313 | kPartitionedWrites1); |
| 21314 | SequencedSocketData partitioned_data2(kPartitionedReads2, |
| 21315 | kPartitionedWrites2); |
| 21316 | |
| 21317 | // No need to segment SSLDataProviders by whether or not partitioning is |
| 21318 | // enabled. |
| 21319 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 21320 | ssl_data1.next_proto = kProtoHTTP2; |
| 21321 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 21322 | ssl_data2.next_proto = kProtoHTTP2; |
| 21323 | |
| 21324 | if (partition_connections) { |
| 21325 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 21326 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21327 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 21328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 21329 | } else { |
| 21330 | session_deps_.socket_factory->AddSocketDataProvider( |
| 21331 | &unpartitioned_data); |
| 21332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21333 | } |
| 21334 | |
| 21335 | TestCompletionCallback callback; |
| 21336 | HttpRequestInfo request1; |
| 21337 | request1.method = "GET"; |
| 21338 | request1.url = GURL(url1); |
| 21339 | request1.traffic_annotation = |
| 21340 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21341 | request1.network_isolation_key = network_isolation_key1; |
| 21342 | auto trans1 = |
| 21343 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21344 | int rv = |
| 21345 | trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21346 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21347 | std::string response_data1; |
| 21348 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21349 | EXPECT_EQ("1", response_data1); |
| 21350 | trans1.reset(); |
| 21351 | |
| 21352 | HttpRequestInfo request2; |
| 21353 | request2.method = "GET"; |
| 21354 | request2.url = GURL(url2); |
| 21355 | request2.traffic_annotation = |
| 21356 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21357 | request2.network_isolation_key = network_isolation_key2; |
| 21358 | auto trans2 = |
| 21359 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21360 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21361 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21362 | std::string response_data2; |
| 21363 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21364 | EXPECT_EQ("2", response_data2); |
| 21365 | trans2.reset(); |
| 21366 | |
| 21367 | HttpRequestInfo request3; |
| 21368 | request3.method = "GET"; |
| 21369 | request3.url = GURL(url3); |
| 21370 | request3.traffic_annotation = |
| 21371 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21372 | request3.network_isolation_key = network_isolation_key1; |
| 21373 | auto trans3 = |
| 21374 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21375 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21376 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21377 | std::string response_data3; |
| 21378 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21379 | EXPECT_EQ("3", response_data3); |
| 21380 | trans3.reset(); |
| 21381 | } |
| 21382 | } |
| 21383 | } |
| 21384 | |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 21385 | // Preconnect two sockets with different NetworkIsolationKeys when |
| 21386 | // features::kPartitionConnectionsByNetworkIsolationKey is enabled. Then issue a |
| 21387 | // request and make sure the correct socket is used. Loops three times, |
| 21388 | // expecting to use the first preconnect, second preconnect, and neither. |
| 21389 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationPreconnect) { |
| 21390 | base::test::ScopedFeatureList feature_list; |
| 21391 | feature_list.InitAndEnableFeature( |
| 21392 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21393 | |
| 21394 | enum class TestCase { |
| 21395 | kUseFirstPreconnect, |
| 21396 | kUseSecondPreconnect, |
| 21397 | kDontUsePreconnect, |
| 21398 | }; |
| 21399 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21400 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21401 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21402 | const auto kOrigin3 = url::Origin::Create(GURL("http://origin3/")); |
| 21403 | NetworkIsolationKey preconnect1_isolation_key(kOrigin1, kOrigin1); |
| 21404 | NetworkIsolationKey preconnect2_isolation_key(kOrigin2, kOrigin2); |
| 21405 | NetworkIsolationKey not_preconnected_isolation_key(kOrigin3, kOrigin3); |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 21406 | |
| 21407 | // Test that only preconnects with |
| 21408 | for (TestCase test_case : |
| 21409 | {TestCase::kUseFirstPreconnect, TestCase::kUseSecondPreconnect, |
| 21410 | TestCase::kDontUsePreconnect}) { |
| 21411 | SpdySessionDependencies session_deps; |
| 21412 | // Make DNS lookups completely synchronously, so preconnects complete |
| 21413 | // immediately. |
| 21414 | session_deps.host_resolver->set_synchronous_mode(true); |
| 21415 | |
| 21416 | const MockWrite kMockWrites[] = { |
| 21417 | MockWrite(ASYNC, 0, |
| 21418 | "GET / HTTP/1.1\r\n" |
| 21419 | "Host: www.foo.com\r\n" |
| 21420 | "Connection: keep-alive\r\n\r\n"), |
| 21421 | }; |
| 21422 | |
| 21423 | const MockRead kMockReads[] = { |
| 21424 | MockRead(ASYNC, 1, |
| 21425 | "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n" |
| 21426 | "hello"), |
| 21427 | }; |
| 21428 | |
| 21429 | // Used for the socket that will actually be used, which may or may not be |
| 21430 | // one of the preconnects |
| 21431 | SequencedSocketData used_socket_data(MockConnect(SYNCHRONOUS, OK), |
| 21432 | kMockReads, kMockWrites); |
| 21433 | |
| 21434 | // Used for the preconnects that won't actually be used. |
| 21435 | SequencedSocketData preconnect1_data(MockConnect(SYNCHRONOUS, OK), |
| 21436 | base::span<const MockRead>(), |
| 21437 | base::span<const MockWrite>()); |
| 21438 | SequencedSocketData preconnect2_data(MockConnect(SYNCHRONOUS, OK), |
| 21439 | base::span<const MockRead>(), |
| 21440 | base::span<const MockWrite>()); |
| 21441 | |
| 21442 | NetworkIsolationKey network_isolation_key_for_request; |
| 21443 | |
| 21444 | switch (test_case) { |
| 21445 | case TestCase::kUseFirstPreconnect: |
| 21446 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21447 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 21448 | network_isolation_key_for_request = preconnect1_isolation_key; |
| 21449 | break; |
| 21450 | case TestCase::kUseSecondPreconnect: |
| 21451 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 21452 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21453 | network_isolation_key_for_request = preconnect2_isolation_key; |
| 21454 | break; |
| 21455 | case TestCase::kDontUsePreconnect: |
| 21456 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 21457 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 21458 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21459 | network_isolation_key_for_request = not_preconnected_isolation_key; |
| 21460 | break; |
| 21461 | } |
| 21462 | |
| 21463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 21464 | |
| 21465 | // Preconnect sockets. |
| 21466 | HttpRequestInfo request; |
| 21467 | request.method = "GET"; |
| 21468 | request.url = GURL("http://www.foo.com/"); |
| 21469 | request.traffic_annotation = |
| 21470 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21471 | |
| 21472 | request.network_isolation_key = preconnect1_isolation_key; |
| 21473 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 21474 | |
| 21475 | request.network_isolation_key = preconnect2_isolation_key; |
| 21476 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 21477 | |
| 21478 | request.network_isolation_key = network_isolation_key_for_request; |
| 21479 | |
| 21480 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21481 | |
| 21482 | // Make the request. |
| 21483 | TestCompletionCallback callback; |
| 21484 | |
| 21485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 21486 | |
| 21487 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 21488 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21489 | |
| 21490 | rv = callback.WaitForResult(); |
| 21491 | EXPECT_THAT(rv, IsOk()); |
| 21492 | |
| 21493 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 21494 | ASSERT_TRUE(response); |
| 21495 | ASSERT_TRUE(response->headers); |
| 21496 | EXPECT_EQ(200, response->headers->response_code()); |
| 21497 | |
| 21498 | std::string response_data; |
| 21499 | rv = ReadTransaction(&trans, &response_data); |
| 21500 | EXPECT_THAT(rv, IsOk()); |
| 21501 | EXPECT_EQ("hello", response_data); |
| 21502 | |
| 21503 | if (test_case != TestCase::kDontUsePreconnect) { |
| 21504 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21505 | } else { |
| 21506 | EXPECT_EQ(3, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21507 | } |
| 21508 | } |
| 21509 | } |
| 21510 | |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21511 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 21512 | // cache is isolated. |
| 21513 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSL) { |
| 21514 | base::test::ScopedFeatureList feature_list; |
| 21515 | feature_list.InitWithFeatures( |
| 21516 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 21517 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 21518 | {}); |
| 21519 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21520 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21521 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21522 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 21523 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21524 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21525 | |
| 21526 | // The server always sends Connection: close, so each request goes over a |
| 21527 | // distinct socket. |
| 21528 | |
| 21529 | const MockWrite kWrites1[] = { |
| 21530 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21531 | "Host: foo.test\r\n" |
| 21532 | "Connection: keep-alive\r\n\r\n")}; |
| 21533 | |
| 21534 | const MockRead kReads1[] = { |
| 21535 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21536 | "Connection: close\r\n" |
| 21537 | "Content-Length: 1\r\n\r\n" |
| 21538 | "1")}; |
| 21539 | |
| 21540 | const MockWrite kWrites2[] = { |
| 21541 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21542 | "Host: foo.test\r\n" |
| 21543 | "Connection: keep-alive\r\n\r\n")}; |
| 21544 | |
| 21545 | const MockRead kReads2[] = { |
| 21546 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21547 | "Connection: close\r\n" |
| 21548 | "Content-Length: 1\r\n\r\n" |
| 21549 | "2")}; |
| 21550 | |
| 21551 | const MockWrite kWrites3[] = { |
| 21552 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21553 | "Host: foo.test\r\n" |
| 21554 | "Connection: keep-alive\r\n\r\n")}; |
| 21555 | |
| 21556 | const MockRead kReads3[] = { |
| 21557 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21558 | "Connection: close\r\n" |
| 21559 | "Content-Length: 1\r\n\r\n" |
| 21560 | "3")}; |
| 21561 | |
| 21562 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21563 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21564 | StaticSocketDataProvider data3(kReads3, kWrites3); |
| 21565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21566 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21567 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 21568 | |
| 21569 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 21570 | ssl_data1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21571 | ssl_data1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21572 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 21573 | ssl_data2.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21574 | ssl_data2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 21575 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
| 21576 | ssl_data3.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21577 | ssl_data3.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21579 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 21580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
| 21581 | |
| 21582 | TestCompletionCallback callback; |
| 21583 | HttpRequestInfo request1; |
| 21584 | request1.method = "GET"; |
| 21585 | request1.url = GURL("https://foo.test/1"); |
| 21586 | request1.traffic_annotation = |
| 21587 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21588 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 21589 | auto trans1 = |
| 21590 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21591 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21592 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21593 | std::string response_data1; |
| 21594 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21595 | EXPECT_EQ("1", response_data1); |
| 21596 | trans1.reset(); |
| 21597 | |
| 21598 | HttpRequestInfo request2; |
| 21599 | request2.method = "GET"; |
| 21600 | request2.url = GURL("https://foo.test/2"); |
| 21601 | request2.traffic_annotation = |
| 21602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21603 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 21604 | auto trans2 = |
| 21605 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21606 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21607 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21608 | std::string response_data2; |
| 21609 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21610 | EXPECT_EQ("2", response_data2); |
| 21611 | trans2.reset(); |
| 21612 | |
| 21613 | HttpRequestInfo request3; |
| 21614 | request3.method = "GET"; |
| 21615 | request3.url = GURL("https://foo.test/3"); |
| 21616 | request3.traffic_annotation = |
| 21617 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21618 | request3.network_isolation_key = kNetworkIsolationKey1; |
| 21619 | auto trans3 = |
| 21620 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21621 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21622 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21623 | std::string response_data3; |
| 21624 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21625 | EXPECT_EQ("3", response_data3); |
| 21626 | trans3.reset(); |
| 21627 | } |
| 21628 | |
| 21629 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 21630 | // cache is isolated, for both origins and proxies. |
| 21631 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSLProxy) { |
| 21632 | base::test::ScopedFeatureList feature_list; |
| 21633 | feature_list.InitWithFeatures( |
| 21634 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 21635 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 21636 | {}); |
| 21637 | |
| 21638 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 21639 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21640 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21641 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21642 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21643 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 21644 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21646 | |
| 21647 | // Make both a tunneled and non-tunneled request. |
| 21648 | HttpRequestInfo request1; |
| 21649 | request1.method = "GET"; |
| 21650 | request1.url = GURL("https://foo.test/1"); |
| 21651 | request1.traffic_annotation = |
| 21652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21653 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 21654 | |
| 21655 | HttpRequestInfo request2; |
| 21656 | request2.method = "GET"; |
| 21657 | request2.url = GURL("http://foo.test/2"); |
| 21658 | request2.traffic_annotation = |
| 21659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21660 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 21661 | |
| 21662 | const MockWrite kWrites1[] = { |
| 21663 | MockWrite("CONNECT foo.test:443 HTTP/1.1\r\n" |
| 21664 | "Host: foo.test:443\r\n" |
| 21665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 21666 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21667 | "Host: foo.test\r\n" |
| 21668 | "Connection: keep-alive\r\n\r\n")}; |
| 21669 | |
| 21670 | const MockRead kReads1[] = { |
| 21671 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 21672 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21673 | "Connection: close\r\n" |
| 21674 | "Content-Length: 1\r\n\r\n" |
| 21675 | "1")}; |
| 21676 | |
| 21677 | const MockWrite kWrites2[] = { |
| 21678 | MockWrite("GET http://foo.test/2 HTTP/1.1\r\n" |
| 21679 | "Host: foo.test\r\n" |
| 21680 | "Proxy-Connection: keep-alive\r\n\r\n")}; |
| 21681 | |
| 21682 | const MockRead kReads2[] = { |
| 21683 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21684 | "Connection: close\r\n" |
| 21685 | "Content-Length: 1\r\n\r\n" |
| 21686 | "2")}; |
| 21687 | |
| 21688 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21689 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21690 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21691 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21692 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21693 | |
| 21694 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 21695 | ssl_proxy1.expected_host_and_port = HostPortPair("myproxy", 70); |
| 21696 | ssl_proxy1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21697 | SSLSocketDataProvider ssl_origin1(ASYNC, OK); |
| 21698 | ssl_origin1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21699 | ssl_origin1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21700 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21701 | ssl_proxy2.expected_host_and_port = HostPortPair("myproxy", 70); |
| 21702 | ssl_proxy2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 21703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 21704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 21705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21706 | |
| 21707 | TestCompletionCallback callback; |
| 21708 | auto trans1 = |
| 21709 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21710 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21711 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21712 | std::string response_data1; |
| 21713 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21714 | EXPECT_EQ("1", response_data1); |
| 21715 | trans1.reset(); |
| 21716 | |
| 21717 | auto trans2 = |
| 21718 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21719 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21720 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21721 | std::string response_data2; |
| 21722 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21723 | EXPECT_EQ("2", response_data2); |
| 21724 | trans2.reset(); |
| 21725 | } |
| 21726 | |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21727 | // Test that SSLConfig changes from SSLConfigService are picked up even when |
| 21728 | // there are live sockets. |
| 21729 | TEST_F(HttpNetworkTransactionTest, SSLConfigChanged) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21730 | SSLContextConfig ssl_context_config; |
| 21731 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21732 | auto ssl_config_service = |
| 21733 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21734 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 21735 | |
| 21736 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 21737 | |
| 21738 | // Make three requests. Between the second and third, the SSL config will |
| 21739 | // change. |
| 21740 | HttpRequestInfo request1; |
| 21741 | request1.method = "GET"; |
| 21742 | request1.url = GURL("https://foo.test/1"); |
| 21743 | request1.traffic_annotation = |
| 21744 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21745 | |
| 21746 | HttpRequestInfo request2; |
| 21747 | request2.method = "GET"; |
| 21748 | request2.url = GURL("https://foo.test/2"); |
| 21749 | request2.traffic_annotation = |
| 21750 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21751 | |
| 21752 | HttpRequestInfo request3; |
| 21753 | request3.method = "GET"; |
| 21754 | request3.url = GURL("https://foo.test/3"); |
| 21755 | request3.traffic_annotation = |
| 21756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21757 | |
| 21758 | const MockWrite kWrites1[] = { |
| 21759 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21760 | "Host: foo.test\r\n" |
| 21761 | "Connection: keep-alive\r\n\r\n"), |
| 21762 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21763 | "Host: foo.test\r\n" |
| 21764 | "Connection: keep-alive\r\n\r\n"), |
| 21765 | }; |
| 21766 | |
| 21767 | const MockRead kReads1[] = { |
| 21768 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21769 | "Connection: keep-alive\r\n" |
| 21770 | "Content-Length: 1\r\n\r\n" |
| 21771 | "1"), |
| 21772 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21773 | "Connection: keep-alive\r\n" |
| 21774 | "Content-Length: 1\r\n\r\n" |
| 21775 | "2"), |
| 21776 | }; |
| 21777 | |
| 21778 | // The third request goes on a different socket because the SSL config has |
| 21779 | // changed. |
| 21780 | const MockWrite kWrites2[] = { |
| 21781 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21782 | "Host: foo.test\r\n" |
| 21783 | "Connection: keep-alive\r\n\r\n")}; |
| 21784 | |
| 21785 | const MockRead kReads2[] = { |
| 21786 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21787 | "Connection: keep-alive\r\n" |
| 21788 | "Content-Length: 1\r\n\r\n" |
| 21789 | "3")}; |
| 21790 | |
| 21791 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21792 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21793 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21794 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21795 | |
| 21796 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 21797 | ssl1.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21798 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 21799 | ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 21800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21802 | |
| 21803 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 21804 | |
| 21805 | TestCompletionCallback callback; |
| 21806 | auto trans1 = |
| 21807 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21808 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21809 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21810 | std::string response_data1; |
| 21811 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21812 | EXPECT_EQ("1", response_data1); |
| 21813 | trans1.reset(); |
| 21814 | |
| 21815 | auto trans2 = |
| 21816 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21817 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21818 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21819 | std::string response_data2; |
| 21820 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21821 | EXPECT_EQ("2", response_data2); |
| 21822 | trans2.reset(); |
| 21823 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21824 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 21825 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21826 | |
| 21827 | auto trans3 = |
| 21828 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21829 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21830 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21831 | std::string response_data3; |
| 21832 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21833 | EXPECT_EQ("3", response_data3); |
| 21834 | trans3.reset(); |
| 21835 | } |
| 21836 | |
| 21837 | TEST_F(HttpNetworkTransactionTest, SSLConfigChangedPendingConnect) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21838 | SSLContextConfig ssl_context_config; |
| 21839 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21840 | auto ssl_config_service = |
| 21841 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21842 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 21843 | |
| 21844 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 21845 | |
| 21846 | HttpRequestInfo request; |
| 21847 | request.method = "GET"; |
| 21848 | request.url = GURL("https://foo.test/1"); |
| 21849 | request.traffic_annotation = |
| 21850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21851 | |
| 21852 | // Make a socket which never connects. |
| 21853 | StaticSocketDataProvider data({}, {}); |
| 21854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 21855 | SSLSocketDataProvider ssl_data(SYNCHRONOUS, ERR_IO_PENDING); |
| 21856 | ssl_data.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21857 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
| 21858 | |
| 21859 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 21860 | |
| 21861 | TestCompletionCallback callback; |
| 21862 | auto trans = |
| 21863 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21864 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 21865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21866 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21867 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 21868 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21869 | |
| 21870 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NETWORK_CHANGED)); |
| 21871 | } |
| 21872 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 21873 | // Test that HttpNetworkTransaction correctly handles existing sockets when the |
| 21874 | // server requests a client certificate post-handshake (via a TLS |
| 21875 | // renegotiation). This is a regression test for https://crbug.com/829184. |
| 21876 | TEST_F(HttpNetworkTransactionTest, PostHandshakeClientCertWithSockets) { |
| 21877 | const MutableNetworkTrafficAnnotationTag kTrafficAnnotation( |
| 21878 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21879 | |
| 21880 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21881 | cert_request_info->host_and_port = HostPortPair("foo.test", 443); |
| 21882 | |
| 21883 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 21884 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21885 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21886 | ASSERT_TRUE(identity); |
| 21887 | |
| 21888 | // This test will make several requests so that, when the client certificate |
| 21889 | // request comes in, we have a socket in use, an idle socket, and a socket for |
| 21890 | // an unrelated host. |
| 21891 | // |
| 21892 | // First, two long-lived requests which do not complete until after the client |
| 21893 | // certificate request. This arranges for sockets to be in use during the |
| 21894 | // request. They should not be interrupted. |
| 21895 | HttpRequestInfo request_long_lived; |
| 21896 | request_long_lived.method = "GET"; |
| 21897 | request_long_lived.url = GURL("https://foo.test/long-lived"); |
| 21898 | request_long_lived.traffic_annotation = kTrafficAnnotation; |
| 21899 | |
| 21900 | HttpRequestInfo request_long_lived_bar; |
| 21901 | request_long_lived_bar.method = "GET"; |
| 21902 | request_long_lived_bar.url = GURL("https://bar.test/long-lived"); |
| 21903 | request_long_lived_bar.traffic_annotation = kTrafficAnnotation; |
| 21904 | |
| 21905 | // Next, make a request that needs client certificates. |
| 21906 | HttpRequestInfo request_auth; |
| 21907 | request_auth.method = "GET"; |
| 21908 | request_auth.url = GURL("https://foo.test/auth"); |
| 21909 | request_auth.traffic_annotation = kTrafficAnnotation; |
| 21910 | |
| 21911 | // Before responding to the challenge, make a request to an unauthenticated |
| 21912 | // endpoint. This will result in an idle socket when the client certificate |
| 21913 | // challenge is resolved. |
| 21914 | HttpRequestInfo request_unauth; |
| 21915 | request_unauth.method = "GET"; |
| 21916 | request_unauth.url = GURL("https://foo.test/unauth"); |
| 21917 | request_unauth.traffic_annotation = kTrafficAnnotation; |
| 21918 | |
| 21919 | // After all the preceding requests complete, end with two additional requests |
| 21920 | // to ensure pre-authentication foo.test sockets are not used and bar.test |
| 21921 | // sockets are unaffected. |
| 21922 | HttpRequestInfo request_post_auth; |
| 21923 | request_post_auth.method = "GET"; |
| 21924 | request_post_auth.url = GURL("https://foo.test/post-auth"); |
| 21925 | request_post_auth.traffic_annotation = kTrafficAnnotation; |
| 21926 | |
| 21927 | HttpRequestInfo request_post_auth_bar; |
| 21928 | request_post_auth_bar.method = "GET"; |
| 21929 | request_post_auth_bar.url = GURL("https://bar.test/post-auth"); |
| 21930 | request_post_auth_bar.traffic_annotation = kTrafficAnnotation; |
| 21931 | |
| 21932 | // The sockets for /long-lived and /unauth complete their request but are |
| 21933 | // not allocated for /post-auth or /retry because SSL state has since changed. |
| 21934 | const MockWrite kLongLivedWrites[] = { |
| 21935 | MockWrite(ASYNC, 0, |
| 21936 | "GET /long-lived HTTP/1.1\r\n" |
| 21937 | "Host: foo.test\r\n" |
| 21938 | "Connection: keep-alive\r\n\r\n"), |
| 21939 | }; |
| 21940 | const MockRead kLongLivedReads[] = { |
| 21941 | // Pause so /long-lived completes after the client presents client |
| 21942 | // certificates. |
| 21943 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 21944 | MockRead(ASYNC, 2, |
| 21945 | "HTTP/1.1 200 OK\r\n" |
| 21946 | "Connection: keep-alive\r\n" |
| 21947 | "Content-Length: 10\r\n\r\n" |
| 21948 | "long-lived"), |
| 21949 | }; |
| 21950 | SequencedSocketData data_long_lived(kLongLivedReads, kLongLivedWrites); |
| 21951 | SSLSocketDataProvider ssl_long_lived(ASYNC, OK); |
| 21952 | session_deps_.socket_factory->AddSocketDataProvider(&data_long_lived); |
| 21953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_long_lived); |
| 21954 | |
| 21955 | // Requests for bar.test should be unaffected by foo.test and get allocated |
| 21956 | // a single socket. |
| 21957 | const MockWrite kBarWrites[] = { |
| 21958 | MockWrite(ASYNC, 0, |
| 21959 | "GET /long-lived HTTP/1.1\r\n" |
| 21960 | "Host: bar.test\r\n" |
| 21961 | "Connection: keep-alive\r\n\r\n"), |
| 21962 | MockWrite(ASYNC, 3, |
| 21963 | "GET /post-auth HTTP/1.1\r\n" |
| 21964 | "Host: bar.test\r\n" |
| 21965 | "Connection: keep-alive\r\n\r\n"), |
| 21966 | }; |
| 21967 | const MockRead kBarReads[] = { |
| 21968 | // Pause on /long-lived so it completes after foo.test's authentication. |
| 21969 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 21970 | MockRead(ASYNC, 2, |
| 21971 | "HTTP/1.1 200 OK\r\n" |
| 21972 | "Connection: keep-alive\r\n" |
| 21973 | "Content-Length: 10\r\n\r\n" |
| 21974 | "long-lived"), |
| 21975 | MockRead(ASYNC, 4, |
| 21976 | "HTTP/1.1 200 OK\r\n" |
| 21977 | "Connection: keep-alive\r\n" |
| 21978 | "Content-Length: 9\r\n\r\n" |
| 21979 | "post-auth"), |
| 21980 | }; |
| 21981 | SequencedSocketData data_bar(kBarReads, kBarWrites); |
| 21982 | SSLSocketDataProvider ssl_bar(ASYNC, OK); |
| 21983 | session_deps_.socket_factory->AddSocketDataProvider(&data_bar); |
| 21984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bar); |
| 21985 | |
| 21986 | // Requesting /auth results in a post-handshake client certificate challenge. |
| 21987 | const MockWrite kAuthWrites[] = { |
| 21988 | MockWrite(ASYNC, 0, |
| 21989 | "GET /auth HTTP/1.1\r\n" |
| 21990 | "Host: foo.test\r\n" |
| 21991 | "Connection: keep-alive\r\n\r\n"), |
| 21992 | }; |
| 21993 | const MockRead kAuthReads[] = { |
| 21994 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED, 1), |
| 21995 | }; |
| 21996 | SequencedSocketData data_auth(kAuthReads, kAuthWrites); |
| 21997 | SSLSocketDataProvider ssl_auth(ASYNC, OK); |
| 21998 | ssl_auth.cert_request_info = cert_request_info.get(); |
| 21999 | session_deps_.socket_factory->AddSocketDataProvider(&data_auth); |
| 22000 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_auth); |
| 22001 | |
| 22002 | // Requesting /unauth completes. |
| 22003 | const MockWrite kUnauthWrites[] = { |
| 22004 | MockWrite(ASYNC, 0, |
| 22005 | "GET /unauth HTTP/1.1\r\n" |
| 22006 | "Host: foo.test\r\n" |
| 22007 | "Connection: keep-alive\r\n\r\n"), |
| 22008 | }; |
| 22009 | const MockRead kUnauthReads[] = { |
| 22010 | MockRead(ASYNC, 1, |
| 22011 | "HTTP/1.1 200 OK\r\n" |
| 22012 | "Connection: keep-alive\r\n" |
| 22013 | "Content-Length: 6\r\n\r\n" |
| 22014 | "unauth"), |
| 22015 | }; |
| 22016 | SequencedSocketData data_unauth(kUnauthReads, kUnauthWrites); |
| 22017 | SSLSocketDataProvider ssl_unauth(ASYNC, OK); |
| 22018 | session_deps_.socket_factory->AddSocketDataProvider(&data_unauth); |
| 22019 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_unauth); |
| 22020 | |
| 22021 | // When the client certificate is selected, /auth is retried on a new |
| 22022 | // connection. In particular, it should not be retried on |data_unauth|, |
| 22023 | // which would not honor the new client certificate configuration. |
| 22024 | const MockWrite kRetryWrites[] = { |
| 22025 | MockWrite(ASYNC, 0, |
| 22026 | "GET /auth HTTP/1.1\r\n" |
| 22027 | "Host: foo.test\r\n" |
| 22028 | "Connection: keep-alive\r\n\r\n"), |
| 22029 | }; |
| 22030 | const MockRead kRetryReads[] = { |
| 22031 | MockRead(ASYNC, 1, |
| 22032 | "HTTP/1.1 200 OK\r\n" |
| 22033 | // Close the connection so we test that /post-auth is not |
| 22034 | // allocated to |data_unauth| or |data_long_lived|. |
| 22035 | "Connection: close\r\n" |
| 22036 | "Content-Length: 4\r\n\r\n" |
| 22037 | "auth"), |
| 22038 | }; |
| 22039 | SequencedSocketData data_retry(kRetryReads, kRetryWrites); |
| 22040 | SSLSocketDataProvider ssl_retry(ASYNC, OK); |
| 22041 | ssl_retry.expected_send_client_cert = true; |
| 22042 | ssl_retry.expected_client_cert = identity->certificate(); |
| 22043 | session_deps_.socket_factory->AddSocketDataProvider(&data_retry); |
| 22044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_retry); |
| 22045 | |
| 22046 | // /post-auth gets its own socket. |
| 22047 | const MockWrite kPostAuthWrites[] = { |
| 22048 | MockWrite(ASYNC, 0, |
| 22049 | "GET /post-auth HTTP/1.1\r\n" |
| 22050 | "Host: foo.test\r\n" |
| 22051 | "Connection: keep-alive\r\n\r\n"), |
| 22052 | }; |
| 22053 | const MockRead kPostAuthReads[] = { |
| 22054 | MockRead(ASYNC, 1, |
| 22055 | "HTTP/1.1 200 OK\r\n" |
| 22056 | "Connection: keep-alive\r\n" |
| 22057 | "Content-Length: 9\r\n\r\n" |
| 22058 | "post-auth"), |
| 22059 | }; |
| 22060 | SequencedSocketData data_post_auth(kPostAuthReads, kPostAuthWrites); |
| 22061 | SSLSocketDataProvider ssl_post_auth(ASYNC, OK); |
| 22062 | ssl_post_auth.expected_send_client_cert = true; |
| 22063 | ssl_post_auth.expected_client_cert = identity->certificate(); |
| 22064 | session_deps_.socket_factory->AddSocketDataProvider(&data_post_auth); |
| 22065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_post_auth); |
| 22066 | |
| 22067 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22068 | |
| 22069 | // Start the two long-lived requests. |
| 22070 | TestCompletionCallback callback_long_lived; |
| 22071 | auto trans_long_lived = |
| 22072 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22073 | int rv = trans_long_lived->Start( |
| 22074 | &request_long_lived, callback_long_lived.callback(), NetLogWithSource()); |
| 22075 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22076 | data_long_lived.RunUntilPaused(); |
| 22077 | |
| 22078 | TestCompletionCallback callback_long_lived_bar; |
| 22079 | auto trans_long_lived_bar = |
| 22080 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22081 | rv = trans_long_lived_bar->Start(&request_long_lived_bar, |
| 22082 | callback_long_lived_bar.callback(), |
| 22083 | NetLogWithSource()); |
| 22084 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22085 | data_bar.RunUntilPaused(); |
| 22086 | |
| 22087 | // Request /auth. This gives a client certificate challenge. |
| 22088 | TestCompletionCallback callback_auth; |
| 22089 | auto trans_auth = |
| 22090 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22091 | rv = trans_auth->Start(&request_auth, callback_auth.callback(), |
| 22092 | NetLogWithSource()); |
| 22093 | EXPECT_THAT(callback_auth.GetResult(rv), |
| 22094 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 22095 | |
| 22096 | // Make an unauthenticated request. This completes. |
| 22097 | TestCompletionCallback callback_unauth; |
| 22098 | auto trans_unauth = |
| 22099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22100 | rv = trans_unauth->Start(&request_unauth, callback_unauth.callback(), |
| 22101 | NetLogWithSource()); |
| 22102 | EXPECT_THAT(callback_unauth.GetResult(rv), IsOk()); |
| 22103 | std::string response_unauth; |
| 22104 | EXPECT_THAT(ReadTransaction(trans_unauth.get(), &response_unauth), IsOk()); |
| 22105 | EXPECT_EQ("unauth", response_unauth); |
| 22106 | trans_unauth.reset(); |
| 22107 | |
| 22108 | // Complete the authenticated request. |
| 22109 | rv = trans_auth->RestartWithCertificate(identity->certificate(), |
| 22110 | identity->ssl_private_key(), |
| 22111 | callback_auth.callback()); |
| 22112 | EXPECT_THAT(callback_auth.GetResult(rv), IsOk()); |
| 22113 | std::string response_auth; |
| 22114 | EXPECT_THAT(ReadTransaction(trans_auth.get(), &response_auth), IsOk()); |
| 22115 | EXPECT_EQ("auth", response_auth); |
| 22116 | trans_auth.reset(); |
| 22117 | |
| 22118 | // Complete the long-lived requests. |
| 22119 | data_long_lived.Resume(); |
| 22120 | EXPECT_THAT(callback_long_lived.GetResult(ERR_IO_PENDING), IsOk()); |
| 22121 | std::string response_long_lived; |
| 22122 | EXPECT_THAT(ReadTransaction(trans_long_lived.get(), &response_long_lived), |
| 22123 | IsOk()); |
| 22124 | EXPECT_EQ("long-lived", response_long_lived); |
| 22125 | trans_long_lived.reset(); |
| 22126 | |
| 22127 | data_bar.Resume(); |
| 22128 | EXPECT_THAT(callback_long_lived_bar.GetResult(ERR_IO_PENDING), IsOk()); |
| 22129 | std::string response_long_lived_bar; |
| 22130 | EXPECT_THAT( |
| 22131 | ReadTransaction(trans_long_lived_bar.get(), &response_long_lived_bar), |
| 22132 | IsOk()); |
| 22133 | EXPECT_EQ("long-lived", response_long_lived_bar); |
| 22134 | trans_long_lived_bar.reset(); |
| 22135 | |
| 22136 | // Run the post-authentication requests. |
| 22137 | TestCompletionCallback callback_post_auth; |
| 22138 | auto trans_post_auth = |
| 22139 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22140 | rv = trans_post_auth->Start(&request_post_auth, callback_post_auth.callback(), |
| 22141 | NetLogWithSource()); |
| 22142 | EXPECT_THAT(callback_post_auth.GetResult(rv), IsOk()); |
| 22143 | std::string response_post_auth; |
| 22144 | EXPECT_THAT(ReadTransaction(trans_post_auth.get(), &response_post_auth), |
| 22145 | IsOk()); |
| 22146 | EXPECT_EQ("post-auth", response_post_auth); |
| 22147 | trans_post_auth.reset(); |
| 22148 | |
| 22149 | TestCompletionCallback callback_post_auth_bar; |
| 22150 | auto trans_post_auth_bar = |
| 22151 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22152 | rv = trans_post_auth_bar->Start(&request_post_auth_bar, |
| 22153 | callback_post_auth_bar.callback(), |
| 22154 | NetLogWithSource()); |
| 22155 | EXPECT_THAT(callback_post_auth_bar.GetResult(rv), IsOk()); |
| 22156 | std::string response_post_auth_bar; |
| 22157 | EXPECT_THAT( |
| 22158 | ReadTransaction(trans_post_auth_bar.get(), &response_post_auth_bar), |
| 22159 | IsOk()); |
| 22160 | EXPECT_EQ("post-auth", response_post_auth_bar); |
| 22161 | trans_post_auth_bar.reset(); |
| 22162 | } |
| 22163 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 22164 | } // namespace net |