[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 | b5e433e6 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | 42834111 | 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 | b5e433e6 | 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 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame^] | 3341 | // Check that credentials were successfully cached, with the right target. |
| 3342 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 3343 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 3344 | HttpAuth::AUTH_SCHEME_BASIC); |
| 3345 | ASSERT_TRUE(entry); |
| 3346 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 3347 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 3348 | |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3349 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3350 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3351 | |
| 3352 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3353 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3354 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3355 | |
| 3356 | trans.reset(); |
| 3357 | session->CloseAllConnections(); |
| 3358 | } |
| 3359 | |
| 3360 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3361 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3362 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3363 | HttpRequestInfo request; |
| 3364 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3365 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3366 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3367 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3368 | request.traffic_annotation = |
| 3369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3370 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3371 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3372 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3373 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3374 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3375 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3376 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3378 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3379 | // Since we have proxy, should try to establish tunnel. |
| 3380 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3381 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3382 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3383 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3384 | }; |
| 3385 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3386 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3387 | // connection. |
| 3388 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3389 | // No credentials. |
| 3390 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3391 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3392 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3393 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3394 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3395 | MockWrite data_writes2[] = { |
| 3396 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3397 | // be issuing -- the final header line contains the credentials. |
| 3398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3399 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3400 | "Proxy-Connection: keep-alive\r\n" |
| 3401 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3402 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3403 | MockWrite("GET / HTTP/1.1\r\n" |
| 3404 | "Host: www.example.org\r\n" |
| 3405 | "Connection: keep-alive\r\n\r\n"), |
| 3406 | }; |
| 3407 | |
| 3408 | MockRead data_reads2[] = { |
| 3409 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3410 | |
| 3411 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3412 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3413 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3414 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3415 | }; |
| 3416 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3417 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3418 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3419 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3421 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3424 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3425 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3426 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3428 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3429 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3431 | |
| 3432 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3433 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3434 | auto entries = log.GetEntries(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3435 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3436 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3437 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3438 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3439 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3440 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3441 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3442 | |
| 3443 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3444 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3445 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3446 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3447 | EXPECT_EQ(407, response->headers->response_code()); |
| 3448 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3449 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3450 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3451 | LoadTimingInfo load_timing_info; |
| 3452 | // CONNECT requests and responses are handled at the connect job level, so |
| 3453 | // the transaction does not yet have a connection. |
| 3454 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3456 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3458 | rv = trans->RestartWithAuth( |
| 3459 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3461 | |
| 3462 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3463 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3464 | |
| 3465 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3466 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | |
| 3468 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3469 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3470 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3471 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3472 | |
| 3473 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3474 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3475 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3476 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3477 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3478 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3479 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3480 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3481 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3482 | } |
| 3483 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3484 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3485 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3486 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3487 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3488 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3489 | // reused. See http://crbug.com/544255. |
| 3490 | for (int i = 0; i < 2; ++i) { |
| 3491 | HttpRequestInfo request; |
| 3492 | request.method = "GET"; |
| 3493 | request.url = GURL("https://www.example.org/"); |
| 3494 | // Ensure that proxy authentication is attempted even |
| 3495 | // when the no authentication data flag is set. |
| 3496 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3497 | request.traffic_annotation = |
| 3498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3499 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3500 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3501 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3502 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3503 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3504 | BoundTestNetLog log; |
| 3505 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3509 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3510 | // Since we have proxy, should try to establish tunnel. |
| 3511 | MockWrite data_writes1[] = { |
| 3512 | MockWrite(ASYNC, 0, |
| 3513 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3514 | "Host: www.example.org:443\r\n" |
| 3515 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3517 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3518 | // be issuing -- the final header line contains the credentials. |
| 3519 | MockWrite(ASYNC, 3, |
| 3520 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3521 | "Host: www.example.org:443\r\n" |
| 3522 | "Proxy-Connection: keep-alive\r\n" |
| 3523 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3524 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3525 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3526 | // The proxy responds to the connect with a 407, using a persistent |
| 3527 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3528 | MockRead data_reads1[] = { |
| 3529 | // No credentials. |
| 3530 | MockRead(ASYNC, 1, |
| 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 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | // Wrong credentials (wrong password). |
| 3538 | MockRead(ASYNC, 4, |
| 3539 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3540 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3541 | "Proxy-Connection: keep-alive\r\n" |
| 3542 | "Content-Length: 10\r\n\r\n"), |
| 3543 | // No response body because the test stops reading here. |
| 3544 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3545 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3546 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3547 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3548 | data1.set_busy_before_sync_reads(true); |
| 3549 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3550 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3551 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3552 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3553 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3554 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3555 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3556 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3558 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3559 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3560 | ExpectLogContainsSomewhere( |
| 3561 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3562 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3563 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3564 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3565 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | ASSERT_TRUE(response); |
| 3567 | ASSERT_TRUE(response->headers); |
| 3568 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3569 | EXPECT_EQ(407, response->headers->response_code()); |
| 3570 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3571 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3572 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3573 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3574 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3575 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3576 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3577 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3578 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3579 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3581 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3582 | ASSERT_TRUE(response); |
| 3583 | ASSERT_TRUE(response->headers); |
| 3584 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3585 | EXPECT_EQ(407, response->headers->response_code()); |
| 3586 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3587 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3588 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3591 | // out of scope. |
| 3592 | session->CloseAllConnections(); |
| 3593 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3597 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3598 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3599 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3600 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3601 | // reused. See http://crbug.com/544255. |
| 3602 | for (int i = 0; i < 2; ++i) { |
| 3603 | HttpRequestInfo request; |
| 3604 | request.method = "GET"; |
| 3605 | request.url = GURL("https://www.example.org/"); |
| 3606 | // Ensure that proxy authentication is attempted even |
| 3607 | // when the no authentication data flag is set. |
| 3608 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3609 | request.traffic_annotation = |
| 3610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | |
| 3612 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3613 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3614 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3615 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3616 | BoundTestNetLog log; |
| 3617 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3621 | |
| 3622 | // Since we have proxy, should try to establish tunnel. |
| 3623 | MockWrite data_writes1[] = { |
| 3624 | MockWrite(ASYNC, 0, |
| 3625 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3626 | "Host: www.example.org:443\r\n" |
| 3627 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3629 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3630 | // be issuing -- the final header line contains the credentials. |
| 3631 | MockWrite(ASYNC, 3, |
| 3632 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3633 | "Host: www.example.org:443\r\n" |
| 3634 | "Proxy-Connection: keep-alive\r\n" |
| 3635 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3636 | }; |
| 3637 | |
| 3638 | // The proxy responds to the connect with a 407, using a persistent |
| 3639 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3640 | MockRead data_reads1[] = { |
| 3641 | // No credentials. |
| 3642 | MockRead(ASYNC, 1, |
| 3643 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3644 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3645 | "Content-Length: 10\r\n\r\n"), |
| 3646 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3647 | |
| 3648 | // Wrong credentials (wrong password). |
| 3649 | MockRead(ASYNC, 4, |
| 3650 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3651 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3652 | "Content-Length: 10\r\n\r\n"), |
| 3653 | // No response body because the test stops reading here. |
| 3654 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3655 | }; |
| 3656 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3657 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3658 | data1.set_busy_before_sync_reads(true); |
| 3659 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3660 | |
| 3661 | TestCompletionCallback callback1; |
| 3662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3663 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3664 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3665 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3666 | auto entries = log.GetEntries(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3667 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3668 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3669 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3670 | ExpectLogContainsSomewhere( |
| 3671 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3672 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3673 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | ASSERT_TRUE(response); |
| 3677 | ASSERT_TRUE(response->headers); |
| 3678 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3679 | EXPECT_EQ(407, response->headers->response_code()); |
| 3680 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3681 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3682 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3683 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3684 | |
| 3685 | TestCompletionCallback callback2; |
| 3686 | |
| 3687 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3689 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3690 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3692 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3693 | ASSERT_TRUE(response); |
| 3694 | ASSERT_TRUE(response->headers); |
| 3695 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3696 | EXPECT_EQ(407, response->headers->response_code()); |
| 3697 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3698 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3699 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3700 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3701 | |
| 3702 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3703 | // out of scope. |
| 3704 | session->CloseAllConnections(); |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3709 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3710 | // the case the server sends extra data on the original socket, so it can't be |
| 3711 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3712 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3713 | HttpRequestInfo request; |
| 3714 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3715 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3716 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3717 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3718 | request.traffic_annotation = |
| 3719 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3720 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3721 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3722 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3723 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3724 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3725 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3726 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3728 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3729 | // Since we have proxy, should try to establish tunnel. |
| 3730 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3731 | MockWrite(ASYNC, 0, |
| 3732 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3733 | "Host: www.example.org:443\r\n" |
| 3734 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3735 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3736 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3737 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3738 | // extra data, so the socket cannot be reused. |
| 3739 | MockRead data_reads1[] = { |
| 3740 | // No credentials. |
| 3741 | MockRead(ASYNC, 1, |
| 3742 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3743 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3744 | "Content-Length: 10\r\n\r\n"), |
| 3745 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3746 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3747 | }; |
| 3748 | |
| 3749 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3750 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3751 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3752 | MockWrite(ASYNC, 0, |
| 3753 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3754 | "Host: www.example.org:443\r\n" |
| 3755 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3756 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3757 | |
| 3758 | MockWrite(ASYNC, 2, |
| 3759 | "GET / HTTP/1.1\r\n" |
| 3760 | "Host: www.example.org\r\n" |
| 3761 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3762 | }; |
| 3763 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3764 | MockRead data_reads2[] = { |
| 3765 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3766 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3767 | MockRead(ASYNC, 3, |
| 3768 | "HTTP/1.1 200 OK\r\n" |
| 3769 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3770 | "Content-Length: 5\r\n\r\n"), |
| 3771 | // No response body because the test stops reading here. |
| 3772 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3773 | }; |
| 3774 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3775 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3776 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3777 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3778 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3779 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3780 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3783 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3784 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3785 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3787 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3788 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3789 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3790 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 3791 | auto entries = log.GetEntries(); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3792 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3793 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3794 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3795 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3796 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3797 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3798 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3799 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3800 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3801 | ASSERT_TRUE(response); |
| 3802 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3803 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3804 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3805 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3806 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3807 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3808 | LoadTimingInfo load_timing_info; |
| 3809 | // CONNECT requests and responses are handled at the connect job level, so |
| 3810 | // the transaction does not yet have a connection. |
| 3811 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3812 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3813 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3814 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3815 | rv = |
| 3816 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3817 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3818 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3819 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3820 | EXPECT_EQ(200, response->headers->response_code()); |
| 3821 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3822 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3823 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3824 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3825 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3826 | |
| 3827 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3828 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3829 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3830 | |
| 3831 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3832 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3833 | } |
| 3834 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3835 | // Test the case a proxy closes a socket while the challenge body is being |
| 3836 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3837 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3838 | HttpRequestInfo request; |
| 3839 | request.method = "GET"; |
| 3840 | request.url = GURL("https://www.example.org/"); |
| 3841 | // Ensure that proxy authentication is attempted even |
| 3842 | // when the no authentication data flag is set. |
| 3843 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3844 | request.traffic_annotation = |
| 3845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3846 | |
| 3847 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3848 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3849 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3850 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3853 | |
| 3854 | // Since we have proxy, should try to establish tunnel. |
| 3855 | MockWrite data_writes1[] = { |
| 3856 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3857 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3858 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3859 | }; |
| 3860 | |
| 3861 | // The proxy responds to the connect with a 407, using a persistent |
| 3862 | // connection. |
| 3863 | MockRead data_reads1[] = { |
| 3864 | // No credentials. |
| 3865 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3866 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3867 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3868 | // Server hands up in the middle of the body. |
| 3869 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3870 | }; |
| 3871 | |
| 3872 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3873 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3874 | // be issuing -- the final header line contains the credentials. |
| 3875 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3876 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3877 | "Proxy-Connection: keep-alive\r\n" |
| 3878 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3879 | |
| 3880 | MockWrite("GET / HTTP/1.1\r\n" |
| 3881 | "Host: www.example.org\r\n" |
| 3882 | "Connection: keep-alive\r\n\r\n"), |
| 3883 | }; |
| 3884 | |
| 3885 | MockRead data_reads2[] = { |
| 3886 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3887 | |
| 3888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3889 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3890 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3891 | MockRead(SYNCHRONOUS, "hello"), |
| 3892 | }; |
| 3893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3894 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3896 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3897 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3898 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3900 | |
| 3901 | TestCompletionCallback callback; |
| 3902 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3904 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3906 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3907 | ASSERT_TRUE(response); |
| 3908 | ASSERT_TRUE(response->headers); |
| 3909 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3910 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3911 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3913 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3914 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3916 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3917 | ASSERT_TRUE(response); |
| 3918 | ASSERT_TRUE(response->headers); |
| 3919 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3920 | EXPECT_EQ(200, response->headers->response_code()); |
| 3921 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3922 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3923 | EXPECT_EQ("hello", body); |
| 3924 | } |
| 3925 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3926 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3927 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3928 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3929 | HttpRequestInfo request; |
| 3930 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3931 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3932 | request.traffic_annotation = |
| 3933 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3934 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3935 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3936 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3937 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3942 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3943 | // Since we have proxy, should try to establish tunnel. |
| 3944 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3945 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3946 | "Host: www.example.org:443\r\n" |
| 3947 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3948 | }; |
| 3949 | |
| 3950 | // The proxy responds to the connect with a 407. |
| 3951 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3952 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3953 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3954 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3955 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3956 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3957 | }; |
| 3958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3959 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3961 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3962 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3963 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 3964 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3966 | |
| 3967 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3968 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3970 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3971 | ASSERT_TRUE(response); |
| 3972 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3973 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3974 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3975 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3976 | |
| 3977 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3978 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3979 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3980 | |
| 3981 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3982 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3983 | } |
| 3984 | |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame^] | 3985 | // Test the no-tunnel HTTP auth case where proxy and server origins and realms |
| 3986 | // are the same, but the user/passwords are different. Serves to verify |
| 3987 | // credentials are correctly separated based on HttpAuth::Target. |
| 3988 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyMatchesServerAuthNoTunnel) { |
| 3989 | HttpRequestInfo request; |
| 3990 | request.method = "GET"; |
| 3991 | request.url = GURL("http://myproxy:70/"); |
| 3992 | request.traffic_annotation = |
| 3993 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3994 | |
| 3995 | // Proxy matches request URL. |
| 3996 | session_deps_.proxy_resolution_service = |
| 3997 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3998 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3999 | BoundTestNetLog log; |
| 4000 | session_deps_.net_log = log.bound().net_log(); |
| 4001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 4002 | |
| 4003 | MockWrite data_writes[] = { |
| 4004 | // Initial request gets a proxy auth challenge. |
| 4005 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4006 | "Host: myproxy:70\r\n" |
| 4007 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4008 | // Rety with proxy auth credentials, which will result in a server auth |
| 4009 | // challenge. |
| 4010 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4011 | "Host: myproxy:70\r\n" |
| 4012 | "Proxy-Connection: keep-alive\r\n" |
| 4013 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 4014 | // Rety with proxy and server auth credentials, which gets a response. |
| 4015 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4016 | "Host: myproxy:70\r\n" |
| 4017 | "Proxy-Connection: keep-alive\r\n" |
| 4018 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4019 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4020 | // A second request should preemptively send the correct proxy and server |
| 4021 | // auth headers. |
| 4022 | MockWrite("GET http://myproxy:70/ HTTP/1.1\r\n" |
| 4023 | "Host: myproxy:70\r\n" |
| 4024 | "Proxy-Connection: keep-alive\r\n" |
| 4025 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 4026 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
| 4027 | }; |
| 4028 | |
| 4029 | MockRead data_reads[] = { |
| 4030 | // Proxy auth challenge. |
| 4031 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 4032 | "Proxy-Connection: keep-alive\r\n" |
| 4033 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4034 | "Content-Length: 0\r\n\r\n"), |
| 4035 | // Server auth challenge. |
| 4036 | MockRead("HTTP/1.0 401 Authentication Required\r\n" |
| 4037 | "Proxy-Connection: keep-alive\r\n" |
| 4038 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 4039 | "Content-Length: 0\r\n\r\n"), |
| 4040 | // Response. |
| 4041 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4042 | "Proxy-Connection: keep-alive\r\n" |
| 4043 | "Content-Length: 5\r\n\r\n" |
| 4044 | "hello"), |
| 4045 | // Response to second request. |
| 4046 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4047 | "Proxy-Connection: keep-alive\r\n" |
| 4048 | "Content-Length: 2\r\n\r\n" |
| 4049 | "hi"), |
| 4050 | }; |
| 4051 | |
| 4052 | StaticSocketDataProvider data(data_reads, data_writes); |
| 4053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4054 | |
| 4055 | TestCompletionCallback callback; |
| 4056 | |
| 4057 | auto trans = |
| 4058 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4059 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4060 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4061 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4062 | ASSERT_TRUE(response); |
| 4063 | ASSERT_TRUE(response->headers); |
| 4064 | EXPECT_EQ(407, response->headers->response_code()); |
| 4065 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
| 4066 | |
| 4067 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 4068 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4069 | response = trans->GetResponseInfo(); |
| 4070 | ASSERT_TRUE(response); |
| 4071 | EXPECT_EQ(401, response->headers->response_code()); |
| 4072 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
| 4073 | EXPECT_EQ("http://myproxy:70", |
| 4074 | response->auth_challenge->challenger.Serialize()); |
| 4075 | EXPECT_EQ("MyRealm1", response->auth_challenge->realm); |
| 4076 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
| 4077 | |
| 4078 | rv = trans->RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 4079 | callback.callback()); |
| 4080 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4081 | response = trans->GetResponseInfo(); |
| 4082 | ASSERT_TRUE(response); |
| 4083 | EXPECT_EQ(200, response->headers->response_code()); |
| 4084 | // The password prompt info should not be set. |
| 4085 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4086 | |
| 4087 | std::string response_data; |
| 4088 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4089 | EXPECT_EQ("hello", response_data); |
| 4090 | |
| 4091 | // Check that the credentials were cached correctly. |
| 4092 | HttpAuthCache::Entry* entry = session->http_auth_cache()->Lookup( |
| 4093 | GURL("http://myproxy:70"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 4094 | HttpAuth::AUTH_SCHEME_BASIC); |
| 4095 | ASSERT_TRUE(entry); |
| 4096 | ASSERT_EQ(kFoo, entry->credentials().username()); |
| 4097 | ASSERT_EQ(kBar, entry->credentials().password()); |
| 4098 | entry = session->http_auth_cache()->Lookup(GURL("http://myproxy:70"), |
| 4099 | HttpAuth::AUTH_SERVER, "MyRealm1", |
| 4100 | HttpAuth::AUTH_SCHEME_BASIC); |
| 4101 | ASSERT_TRUE(entry); |
| 4102 | ASSERT_EQ(kFoo2, entry->credentials().username()); |
| 4103 | ASSERT_EQ(kBar2, entry->credentials().password()); |
| 4104 | |
| 4105 | // Make another request, which should automatically send the correct proxy and |
| 4106 | // server auth credentials and get another response. |
| 4107 | trans = |
| 4108 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4109 | rv = trans->Start(&request, callback.callback(), log.bound()); |
| 4110 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4111 | response = trans->GetResponseInfo(); |
| 4112 | ASSERT_TRUE(response); |
| 4113 | EXPECT_EQ(200, response->headers->response_code()); |
| 4114 | // The password prompt info should not be set. |
| 4115 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 4116 | |
| 4117 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4118 | EXPECT_EQ("hi", response_data); |
| 4119 | |
| 4120 | trans.reset(); |
| 4121 | session->CloseAllConnections(); |
| 4122 | } |
| 4123 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4124 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4125 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4126 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4127 | HttpRequestInfo request; |
| 4128 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4129 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4130 | request.traffic_annotation = |
| 4131 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4132 | |
| 4133 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4134 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4135 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4136 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4140 | |
| 4141 | // Since we have proxy, should try to establish tunnel. |
| 4142 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4143 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4144 | "Host: www.example.org:443\r\n" |
| 4145 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4146 | }; |
| 4147 | |
| 4148 | // The proxy responds to the connect with a 407. |
| 4149 | MockRead data_reads[] = { |
| 4150 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4151 | MockRead("X-Foo: bar\r\n"), |
| 4152 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4153 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4154 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4155 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4156 | }; |
| 4157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4158 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4160 | |
| 4161 | TestCompletionCallback callback; |
| 4162 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4163 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4165 | |
| 4166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4167 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4169 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4170 | ASSERT_TRUE(response); |
| 4171 | ASSERT_TRUE(response->headers); |
| 4172 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4173 | EXPECT_EQ(407, response->headers->response_code()); |
| 4174 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4175 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4176 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4177 | |
| 4178 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4179 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4180 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4181 | |
| 4182 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4183 | session->CloseAllConnections(); |
| 4184 | } |
| 4185 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4186 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4187 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4188 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4189 | HttpRequestInfo request; |
| 4190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4191 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4192 | request.traffic_annotation = |
| 4193 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4194 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4195 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4197 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4198 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4199 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4200 | MockWrite( |
| 4201 | "GET / HTTP/1.1\r\n" |
| 4202 | "Host: www.example.org\r\n" |
| 4203 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4204 | }; |
| 4205 | |
| 4206 | MockRead data_reads1[] = { |
| 4207 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4208 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4209 | // Large content-length -- won't matter, as connection will be reset. |
| 4210 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4211 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4212 | }; |
| 4213 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4214 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4215 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4217 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4218 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4219 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4221 | |
| 4222 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4223 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4224 | } |
| 4225 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4226 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4227 | // through a non-authenticating proxy. The request should fail with |
| 4228 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4229 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4230 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4231 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4232 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4233 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4234 | HttpRequestInfo request; |
| 4235 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4236 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4237 | request.traffic_annotation = |
| 4238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4239 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4240 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4241 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4242 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4243 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4244 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4245 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4246 | // Since we have proxy, should try to establish tunnel. |
| 4247 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4248 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4249 | "Host: www.example.org:443\r\n" |
| 4250 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4251 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4252 | MockWrite("GET / HTTP/1.1\r\n" |
| 4253 | "Host: www.example.org\r\n" |
| 4254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4255 | }; |
| 4256 | |
| 4257 | MockRead data_reads1[] = { |
| 4258 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4259 | |
| 4260 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4261 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4262 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4263 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4264 | }; |
| 4265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4266 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4267 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4268 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4269 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4270 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4271 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4273 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4275 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4277 | |
| 4278 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4279 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 4280 | auto entries = log.GetEntries(); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4281 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4282 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4283 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4284 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4285 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4286 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4287 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4288 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4289 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4291 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4292 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4293 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4294 | HttpRequestInfo request; |
| 4295 | request.method = "GET"; |
| 4296 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4297 | request.traffic_annotation = |
| 4298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4299 | |
| 4300 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4301 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4302 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4303 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4304 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4305 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4307 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4308 | mock_handler->set_allows_default_credentials(true); |
| 4309 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4310 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4311 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4312 | |
| 4313 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4314 | NetLog net_log; |
| 4315 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4316 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4317 | |
| 4318 | // Since we have proxy, should try to establish tunnel. |
| 4319 | MockWrite data_writes1[] = { |
| 4320 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4321 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4322 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4323 | }; |
| 4324 | |
| 4325 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4326 | // connection. |
| 4327 | MockRead data_reads1[] = { |
| 4328 | // No credentials. |
| 4329 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4330 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4331 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4332 | }; |
| 4333 | |
| 4334 | // Since the first connection couldn't be reused, need to establish another |
| 4335 | // once given credentials. |
| 4336 | MockWrite data_writes2[] = { |
| 4337 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4338 | // be issuing -- the final header line contains the credentials. |
| 4339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4340 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4341 | "Proxy-Connection: keep-alive\r\n" |
| 4342 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4343 | |
| 4344 | MockWrite("GET / HTTP/1.1\r\n" |
| 4345 | "Host: www.example.org\r\n" |
| 4346 | "Connection: keep-alive\r\n\r\n"), |
| 4347 | }; |
| 4348 | |
| 4349 | MockRead data_reads2[] = { |
| 4350 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4351 | |
| 4352 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4354 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4355 | MockRead(SYNCHRONOUS, "hello"), |
| 4356 | }; |
| 4357 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4358 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4359 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4360 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4361 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4362 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4364 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4365 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4366 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4367 | |
| 4368 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4369 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4371 | |
| 4372 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4373 | ASSERT_TRUE(response); |
| 4374 | ASSERT_TRUE(response->headers); |
| 4375 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4376 | EXPECT_EQ(407, response->headers->response_code()); |
| 4377 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4378 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4379 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4380 | |
| 4381 | LoadTimingInfo load_timing_info; |
| 4382 | // CONNECT requests and responses are handled at the connect job level, so |
| 4383 | // the transaction does not yet have a connection. |
| 4384 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4385 | |
| 4386 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4387 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4388 | response = trans->GetResponseInfo(); |
| 4389 | ASSERT_TRUE(response); |
| 4390 | ASSERT_TRUE(response->headers); |
| 4391 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4392 | EXPECT_EQ(200, response->headers->response_code()); |
| 4393 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4394 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4395 | |
| 4396 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4397 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4398 | |
| 4399 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4400 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4401 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4402 | |
| 4403 | trans.reset(); |
| 4404 | session->CloseAllConnections(); |
| 4405 | } |
| 4406 | |
| 4407 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4408 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4409 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4410 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4411 | HttpRequestInfo request; |
| 4412 | request.method = "GET"; |
| 4413 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4414 | request.traffic_annotation = |
| 4415 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4416 | |
| 4417 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4418 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4419 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4420 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4421 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4422 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4423 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4424 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4425 | mock_handler->set_allows_default_credentials(true); |
| 4426 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4427 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4428 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4429 | |
| 4430 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4431 | NetLog net_log; |
| 4432 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4433 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4434 | |
| 4435 | // Should try to establish tunnel. |
| 4436 | MockWrite data_writes1[] = { |
| 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 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4442 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4443 | "Proxy-Connection: keep-alive\r\n" |
| 4444 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4445 | }; |
| 4446 | |
| 4447 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4448 | // connection. |
| 4449 | MockRead data_reads1[] = { |
| 4450 | // No credentials. |
| 4451 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4452 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4453 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4454 | }; |
| 4455 | |
| 4456 | // Since the first connection was closed, need to establish another once given |
| 4457 | // credentials. |
| 4458 | MockWrite data_writes2[] = { |
| 4459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4460 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4461 | "Proxy-Connection: keep-alive\r\n" |
| 4462 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4463 | |
| 4464 | MockWrite("GET / HTTP/1.1\r\n" |
| 4465 | "Host: www.example.org\r\n" |
| 4466 | "Connection: keep-alive\r\n\r\n"), |
| 4467 | }; |
| 4468 | |
| 4469 | MockRead data_reads2[] = { |
| 4470 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4471 | |
| 4472 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4473 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4474 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4475 | MockRead(SYNCHRONOUS, "hello"), |
| 4476 | }; |
| 4477 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4478 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4479 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4480 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4481 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4482 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4484 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4485 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4486 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4487 | |
| 4488 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4489 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4490 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4491 | |
| 4492 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4493 | ASSERT_TRUE(response); |
| 4494 | ASSERT_TRUE(response->headers); |
| 4495 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4496 | EXPECT_EQ(407, response->headers->response_code()); |
| 4497 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4498 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4499 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4500 | |
| 4501 | LoadTimingInfo load_timing_info; |
| 4502 | // CONNECT requests and responses are handled at the connect job level, so |
| 4503 | // the transaction does not yet have a connection. |
| 4504 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4505 | |
| 4506 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4507 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4508 | |
| 4509 | response = trans->GetResponseInfo(); |
| 4510 | ASSERT_TRUE(response); |
| 4511 | ASSERT_TRUE(response->headers); |
| 4512 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4513 | EXPECT_EQ(200, response->headers->response_code()); |
| 4514 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4515 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4516 | |
| 4517 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4518 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4519 | |
| 4520 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4521 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4522 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4523 | |
| 4524 | trans.reset(); |
| 4525 | session->CloseAllConnections(); |
| 4526 | } |
| 4527 | |
| 4528 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4529 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4530 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4531 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4532 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4533 | HttpRequestInfo request; |
| 4534 | request.method = "GET"; |
| 4535 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4536 | request.traffic_annotation = |
| 4537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4538 | |
| 4539 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4540 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4541 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4542 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4543 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4544 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4545 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4546 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4547 | mock_handler->set_allows_default_credentials(true); |
| 4548 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4549 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4550 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4551 | |
| 4552 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4553 | NetLog net_log; |
| 4554 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4555 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4556 | |
| 4557 | // Should try to establish tunnel. |
| 4558 | MockWrite data_writes1[] = { |
| 4559 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4560 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4561 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4562 | |
| 4563 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4564 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4565 | "Proxy-Connection: keep-alive\r\n" |
| 4566 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4567 | }; |
| 4568 | |
| 4569 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4570 | // second request is sent. |
| 4571 | MockRead data_reads1[] = { |
| 4572 | // No credentials. |
| 4573 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4574 | MockRead("Content-Length: 0\r\n"), |
| 4575 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4576 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4577 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4578 | }; |
| 4579 | |
| 4580 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4581 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4582 | // request. |
| 4583 | MockWrite data_writes2[] = { |
| 4584 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4585 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4586 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4587 | }; |
| 4588 | |
| 4589 | // The proxy, having had more than enough of us, just hangs up. |
| 4590 | MockRead data_reads2[] = { |
| 4591 | // No credentials. |
| 4592 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4593 | }; |
| 4594 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4595 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4596 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4597 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4598 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4599 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4600 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4601 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4602 | |
| 4603 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4604 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4605 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4606 | |
| 4607 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4608 | ASSERT_TRUE(response); |
| 4609 | ASSERT_TRUE(response->headers); |
| 4610 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4611 | EXPECT_EQ(407, response->headers->response_code()); |
| 4612 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4613 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4614 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4615 | |
| 4616 | LoadTimingInfo load_timing_info; |
| 4617 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4618 | |
| 4619 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4620 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4621 | |
| 4622 | trans.reset(); |
| 4623 | session->CloseAllConnections(); |
| 4624 | } |
| 4625 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4626 | // This test exercises an odd edge case where the proxy closes the connection |
| 4627 | // after the authentication handshake is complete. Presumably this technique is |
| 4628 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4629 | // succeeds, but the user is not authorized to connect to the destination |
| 4630 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4631 | // site. |
| 4632 | TEST_F(HttpNetworkTransactionTest, |
| 4633 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4634 | HttpRequestInfo request; |
| 4635 | request.method = "GET"; |
| 4636 | request.url = GURL("https://www.example.org/"); |
| 4637 | request.traffic_annotation = |
| 4638 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4639 | |
| 4640 | // Configure against proxy server "myproxy:70". |
| 4641 | session_deps_.proxy_resolution_service = |
| 4642 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4643 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4644 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4645 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4646 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4647 | |
| 4648 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4649 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4650 | // was a real network error. |
| 4651 | // |
| 4652 | // The handlers support both default and explicit credentials. The retry |
| 4653 | // mentioned above should be able to reuse the default identity. Thus there |
| 4654 | // should never be a need to prompt for explicit credentials. |
| 4655 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4656 | mock_handler->set_allows_default_credentials(true); |
| 4657 | mock_handler->set_allows_explicit_credentials(true); |
| 4658 | mock_handler->set_connection_based(true); |
| 4659 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4660 | HttpAuth::AUTH_PROXY); |
| 4661 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4662 | mock_handler->set_allows_default_credentials(true); |
| 4663 | mock_handler->set_allows_explicit_credentials(true); |
| 4664 | mock_handler->set_connection_based(true); |
| 4665 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4666 | HttpAuth::AUTH_PROXY); |
| 4667 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4668 | |
| 4669 | NetLog net_log; |
| 4670 | session_deps_.net_log = &net_log; |
| 4671 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4672 | |
| 4673 | // Data for both sockets. |
| 4674 | // |
| 4675 | // Writes are for the tunnel establishment attempts and the |
| 4676 | // authentication handshake. |
| 4677 | MockWrite data_writes1[] = { |
| 4678 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4679 | "Host: www.example.org:443\r\n" |
| 4680 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4681 | |
| 4682 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4683 | "Host: www.example.org:443\r\n" |
| 4684 | "Proxy-Connection: keep-alive\r\n" |
| 4685 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4686 | |
| 4687 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4688 | "Host: www.example.org:443\r\n" |
| 4689 | "Proxy-Connection: keep-alive\r\n" |
| 4690 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4691 | }; |
| 4692 | |
| 4693 | // The server side of the authentication handshake. Note that the response to |
| 4694 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4695 | MockRead data_reads1[] = { |
| 4696 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4697 | MockRead("Content-Length: 0\r\n"), |
| 4698 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4699 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4700 | |
| 4701 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4702 | MockRead("Content-Length: 0\r\n"), |
| 4703 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4704 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4705 | |
| 4706 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4707 | }; |
| 4708 | |
| 4709 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4710 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4711 | |
| 4712 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4713 | // first attempt. |
| 4714 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4715 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4716 | |
| 4717 | auto trans = |
| 4718 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4719 | |
| 4720 | TestCompletionCallback callback; |
| 4721 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4722 | |
| 4723 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4724 | // stack. |
| 4725 | for (int i = 0; i < 4; ++i) { |
| 4726 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4727 | |
| 4728 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4729 | ASSERT_TRUE(response); |
| 4730 | ASSERT_TRUE(response->headers); |
| 4731 | EXPECT_EQ(407, response->headers->response_code()); |
| 4732 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4733 | |
| 4734 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4735 | } |
| 4736 | |
| 4737 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4738 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4739 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4740 | // being the first number, be reached, then lobbest thou thy |
| 4741 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4742 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4743 | |
| 4744 | trans.reset(); |
| 4745 | session->CloseAllConnections(); |
| 4746 | } |
| 4747 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4748 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4749 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4750 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4751 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4752 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4753 | HttpRequestInfo request; |
| 4754 | request.method = "GET"; |
| 4755 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4756 | request.traffic_annotation = |
| 4757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4758 | |
| 4759 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4760 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4761 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4762 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4763 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4764 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4765 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4766 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4767 | mock_handler->set_allows_default_credentials(true); |
| 4768 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4769 | HttpAuth::AUTH_PROXY); |
| 4770 | // Add another handler for the second challenge. It supports default |
| 4771 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4772 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4773 | mock_handler->set_allows_default_credentials(true); |
| 4774 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4775 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4776 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4777 | |
| 4778 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4779 | NetLog net_log; |
| 4780 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4781 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4782 | |
| 4783 | // Should try to establish tunnel. |
| 4784 | MockWrite data_writes1[] = { |
| 4785 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4786 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4788 | }; |
| 4789 | |
| 4790 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4791 | // connection. |
| 4792 | MockRead data_reads1[] = { |
| 4793 | // No credentials. |
| 4794 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4795 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4796 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4797 | }; |
| 4798 | |
| 4799 | // Since the first connection was closed, need to establish another once given |
| 4800 | // credentials. |
| 4801 | MockWrite data_writes2[] = { |
| 4802 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4803 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4804 | "Proxy-Connection: keep-alive\r\n" |
| 4805 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4806 | }; |
| 4807 | |
| 4808 | MockRead data_reads2[] = { |
| 4809 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4810 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4811 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4812 | }; |
| 4813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4814 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4815 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4816 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4818 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4819 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4820 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4821 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4822 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4823 | |
| 4824 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 4825 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4826 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4827 | |
| 4828 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4829 | ASSERT_TRUE(response); |
| 4830 | ASSERT_TRUE(response->headers); |
| 4831 | EXPECT_EQ(407, response->headers->response_code()); |
| 4832 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4833 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4834 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4835 | |
| 4836 | LoadTimingInfo load_timing_info; |
| 4837 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4838 | |
| 4839 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4840 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4841 | response = trans->GetResponseInfo(); |
| 4842 | ASSERT_TRUE(response); |
| 4843 | ASSERT_TRUE(response->headers); |
| 4844 | EXPECT_EQ(407, response->headers->response_code()); |
| 4845 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4846 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4847 | |
| 4848 | trans.reset(); |
| 4849 | session->CloseAllConnections(); |
| 4850 | } |
| 4851 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4852 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4853 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4854 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4855 | // authentication handshake can continue with the same scheme but with a |
| 4856 | // different identity. |
| 4857 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4858 | HttpRequestInfo request; |
| 4859 | request.method = "GET"; |
| 4860 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4861 | request.traffic_annotation = |
| 4862 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4863 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4864 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4865 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4866 | |
| 4867 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4868 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4869 | mock_handler->set_allows_default_credentials(true); |
| 4870 | mock_handler->set_allows_explicit_credentials(true); |
| 4871 | mock_handler->set_connection_based(true); |
| 4872 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4873 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4874 | HttpAuth::AUTH_SERVER); |
| 4875 | |
| 4876 | // Add another handler for the second challenge. It supports default |
| 4877 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4878 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4879 | mock_handler->set_allows_default_credentials(true); |
| 4880 | mock_handler->set_allows_explicit_credentials(true); |
| 4881 | mock_handler->set_connection_based(true); |
| 4882 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4883 | HttpAuth::AUTH_SERVER); |
| 4884 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4885 | |
| 4886 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4887 | |
| 4888 | MockWrite data_writes1[] = { |
| 4889 | MockWrite("GET / HTTP/1.1\r\n" |
| 4890 | "Host: www.example.org\r\n" |
| 4891 | "Connection: keep-alive\r\n\r\n"), |
| 4892 | }; |
| 4893 | |
| 4894 | MockRead data_reads1[] = { |
| 4895 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4896 | "WWW-Authenticate: Mock\r\n" |
| 4897 | "Connection: keep-alive\r\n\r\n"), |
| 4898 | }; |
| 4899 | |
| 4900 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4901 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4902 | // transaction procceds without an authorization header. |
| 4903 | MockWrite data_writes2[] = { |
| 4904 | MockWrite("GET / HTTP/1.1\r\n" |
| 4905 | "Host: www.example.org\r\n" |
| 4906 | "Connection: keep-alive\r\n\r\n"), |
| 4907 | }; |
| 4908 | |
| 4909 | MockRead data_reads2[] = { |
| 4910 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4911 | "WWW-Authenticate: Mock\r\n" |
| 4912 | "Connection: keep-alive\r\n\r\n"), |
| 4913 | }; |
| 4914 | |
| 4915 | MockWrite data_writes3[] = { |
| 4916 | MockWrite("GET / HTTP/1.1\r\n" |
| 4917 | "Host: www.example.org\r\n" |
| 4918 | "Connection: keep-alive\r\n" |
| 4919 | "Authorization: auth_token\r\n\r\n"), |
| 4920 | }; |
| 4921 | |
| 4922 | MockRead data_reads3[] = { |
| 4923 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4924 | "Content-Length: 5\r\n" |
| 4925 | "Content-Type: text/plain\r\n" |
| 4926 | "Connection: keep-alive\r\n\r\n" |
| 4927 | "Hello"), |
| 4928 | }; |
| 4929 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4930 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4932 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4933 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4934 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4935 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4936 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4937 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4938 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4939 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4940 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4941 | |
| 4942 | TestCompletionCallback callback; |
| 4943 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4944 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4945 | |
| 4946 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4947 | ASSERT_TRUE(response); |
| 4948 | ASSERT_TRUE(response->headers); |
| 4949 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4950 | |
| 4951 | // The following three tests assert that an authentication challenge was |
| 4952 | // received and that the stack is ready to respond to the challenge using |
| 4953 | // ambient credentials. |
| 4954 | EXPECT_EQ(401, response->headers->response_code()); |
| 4955 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4956 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4957 | |
| 4958 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4959 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4960 | response = trans->GetResponseInfo(); |
| 4961 | ASSERT_TRUE(response); |
| 4962 | ASSERT_TRUE(response->headers); |
| 4963 | |
| 4964 | // The following three tests assert that an authentication challenge was |
| 4965 | // received and that the stack needs explicit credentials before it is ready |
| 4966 | // to respond to the challenge. |
| 4967 | EXPECT_EQ(401, response->headers->response_code()); |
| 4968 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4969 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4970 | |
| 4971 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4972 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4973 | response = trans->GetResponseInfo(); |
| 4974 | ASSERT_TRUE(response); |
| 4975 | ASSERT_TRUE(response->headers); |
| 4976 | EXPECT_EQ(200, response->headers->response_code()); |
| 4977 | |
| 4978 | trans.reset(); |
| 4979 | session->CloseAllConnections(); |
| 4980 | } |
| 4981 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4982 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4983 | // schemes, based on the path of the URL being requests. |
| 4984 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4985 | public: |
| 4986 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4987 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4988 | |
| 4989 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4990 | |
| 4991 | static HostPortPair ProxyHostPortPair() { |
| 4992 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4993 | } |
| 4994 | |
| 4995 | // ProxyResolver implementation. |
| 4996 | int GetProxyForURL(const GURL& url, |
| 4997 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4998 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4999 | std::unique_ptr<Request>* request, |
| 5000 | const NetLogWithSource& /*net_log*/) override { |
| 5001 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 5002 | results->set_traffic_annotation( |
| 5003 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5004 | if (url.path() == "/socks4") { |
| 5005 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 5006 | return OK; |
| 5007 | } |
| 5008 | if (url.path() == "/socks5") { |
| 5009 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 5010 | return OK; |
| 5011 | } |
| 5012 | if (url.path() == "/http") { |
| 5013 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 5014 | return OK; |
| 5015 | } |
| 5016 | if (url.path() == "/https") { |
| 5017 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 5018 | return OK; |
| 5019 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5020 | if (url.path() == "/https_trusted") { |
| 5021 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5022 | ProxyHostPortPair(), |
| 5023 | true /* is_trusted_proxy */)); |
| 5024 | return OK; |
| 5025 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5026 | NOTREACHED(); |
| 5027 | return ERR_NOT_IMPLEMENTED; |
| 5028 | } |
| 5029 | |
| 5030 | private: |
| 5031 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 5032 | }; |
| 5033 | |
| 5034 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 5035 | : public ProxyResolverFactory { |
| 5036 | public: |
| 5037 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 5038 | : ProxyResolverFactory(false) {} |
| 5039 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5040 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 5041 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 5042 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 5043 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5044 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 5045 | return OK; |
| 5046 | } |
| 5047 | |
| 5048 | private: |
| 5049 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 5050 | }; |
| 5051 | |
| 5052 | // 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] | 5053 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5054 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 5055 | // request to foo.com using proxy.com as an HTTP proxy. |
| 5056 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5057 | session_deps_.proxy_resolution_service = |
| 5058 | std::make_unique<ProxyResolutionService>( |
| 5059 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5060 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5061 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 5062 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5063 | |
| 5064 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 5065 | |
| 5066 | MockWrite socks_writes[] = { |
| 5067 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 5068 | kSOCKS4OkRequestLocalHostPort80Length), |
| 5069 | MockWrite(SYNCHRONOUS, |
| 5070 | "GET /socks4 HTTP/1.1\r\n" |
| 5071 | "Host: test\r\n" |
| 5072 | "Connection: keep-alive\r\n\r\n"), |
| 5073 | }; |
| 5074 | MockRead socks_reads[] = { |
| 5075 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 5076 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5077 | "Connection: keep-alive\r\n" |
| 5078 | "Content-Length: 15\r\n\r\n" |
| 5079 | "SOCKS4 Response"), |
| 5080 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5081 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5082 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 5083 | |
| 5084 | const char kSOCKS5Request[] = { |
| 5085 | 0x05, // Version |
| 5086 | 0x01, // Command (CONNECT) |
| 5087 | 0x00, // Reserved |
| 5088 | 0x03, // Address type (DOMAINNAME) |
| 5089 | 0x04, // Length of domain (4) |
| 5090 | 't', 'e', 's', 't', // Domain string |
| 5091 | 0x00, 0x50, // 16-bit port (80) |
| 5092 | }; |
| 5093 | MockWrite socks5_writes[] = { |
| 5094 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5095 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5096 | MockWrite(SYNCHRONOUS, |
| 5097 | "GET /socks5 HTTP/1.1\r\n" |
| 5098 | "Host: test\r\n" |
| 5099 | "Connection: keep-alive\r\n\r\n"), |
| 5100 | }; |
| 5101 | MockRead socks5_reads[] = { |
| 5102 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5103 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5104 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5105 | "Connection: keep-alive\r\n" |
| 5106 | "Content-Length: 15\r\n\r\n" |
| 5107 | "SOCKS5 Response"), |
| 5108 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5109 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5110 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5111 | |
| 5112 | MockWrite http_writes[] = { |
| 5113 | MockWrite(SYNCHRONOUS, |
| 5114 | "GET http://test/http HTTP/1.1\r\n" |
| 5115 | "Host: test\r\n" |
| 5116 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5117 | }; |
| 5118 | MockRead http_reads[] = { |
| 5119 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5120 | "Proxy-Connection: keep-alive\r\n" |
| 5121 | "Content-Length: 13\r\n\r\n" |
| 5122 | "HTTP Response"), |
| 5123 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5124 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5125 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5126 | |
| 5127 | MockWrite https_writes[] = { |
| 5128 | MockWrite(SYNCHRONOUS, |
| 5129 | "GET http://test/https HTTP/1.1\r\n" |
| 5130 | "Host: test\r\n" |
| 5131 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5132 | }; |
| 5133 | MockRead https_reads[] = { |
| 5134 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5135 | "Proxy-Connection: keep-alive\r\n" |
| 5136 | "Content-Length: 14\r\n\r\n" |
| 5137 | "HTTPS Response"), |
| 5138 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5139 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5140 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5141 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5143 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5144 | MockWrite https_trusted_writes[] = { |
| 5145 | MockWrite(SYNCHRONOUS, |
| 5146 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5147 | "Host: test\r\n" |
| 5148 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5149 | }; |
| 5150 | MockRead https_trusted_reads[] = { |
| 5151 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5152 | "Proxy-Connection: keep-alive\r\n" |
| 5153 | "Content-Length: 22\r\n\r\n" |
| 5154 | "HTTPS Trusted Response"), |
| 5155 | }; |
| 5156 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5157 | https_trusted_writes); |
| 5158 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5159 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5161 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5162 | struct TestCase { |
| 5163 | GURL url; |
| 5164 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5165 | // 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] | 5166 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5167 | int expected_idle_socks4_sockets; |
| 5168 | int expected_idle_socks5_sockets; |
| 5169 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5170 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5171 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5172 | int expected_idle_https_sockets; |
| 5173 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5174 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5175 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5176 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5177 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5178 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5179 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5180 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5181 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5182 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5183 | }; |
| 5184 | |
| 5185 | for (const auto& test_case : kTestCases) { |
| 5186 | HttpRequestInfo request; |
| 5187 | request.method = "GET"; |
| 5188 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5189 | request.traffic_annotation = |
| 5190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5191 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5192 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5193 | session.get()); |
| 5194 | TestCompletionCallback callback; |
| 5195 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5196 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5197 | |
| 5198 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5199 | ASSERT_TRUE(response); |
| 5200 | ASSERT_TRUE(response->headers); |
| 5201 | EXPECT_EQ(200, response->headers->response_code()); |
| 5202 | std::string response_data; |
| 5203 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5204 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5205 | |
| 5206 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5207 | // the next requests. |
| 5208 | trans.reset(); |
| 5209 | base::RunLoop().RunUntilIdle(); |
| 5210 | |
| 5211 | // Check the number of idle sockets in the pool, to make sure that used |
| 5212 | // sockets are indeed being returned to the socket pool. If each request |
| 5213 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5214 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5215 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5216 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5217 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5218 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5219 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5220 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5221 | ProxyHostPortPair())) |
| 5222 | ->IdleSocketCount()); |
| 5223 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5224 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5225 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5226 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5227 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5228 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5229 | ProxyHostPortPair())) |
| 5230 | ->IdleSocketCount()); |
| 5231 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5232 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5233 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5234 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5235 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5236 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5237 | ProxyHostPortPair())) |
| 5238 | ->IdleSocketCount()); |
| 5239 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5240 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5241 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5242 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5243 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5244 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5245 | ProxyHostPortPair())) |
| 5246 | ->IdleSocketCount()); |
| 5247 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5248 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5249 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5250 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5251 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5252 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5253 | ProxyHostPortPair(), |
| 5254 | true /* is_trusted_proxy */)) |
| 5255 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5256 | } |
| 5257 | } |
| 5258 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5259 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5260 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5261 | HttpRequestInfo request1; |
| 5262 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5263 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5264 | request1.traffic_annotation = |
| 5265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5266 | |
| 5267 | HttpRequestInfo request2; |
| 5268 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5269 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5270 | request2.traffic_annotation = |
| 5271 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5272 | |
| 5273 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5274 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5275 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5276 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5277 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5279 | |
| 5280 | // Since we have proxy, should try to establish tunnel. |
| 5281 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5282 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5283 | "Host: www.example.org:443\r\n" |
| 5284 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5285 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5286 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5287 | "Host: www.example.org\r\n" |
| 5288 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5289 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5290 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5291 | "Host: www.example.org\r\n" |
| 5292 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5293 | }; |
| 5294 | |
| 5295 | // The proxy responds to the connect with a 407, using a persistent |
| 5296 | // connection. |
| 5297 | MockRead data_reads1[] = { |
| 5298 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5299 | |
| 5300 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5301 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5302 | MockRead(SYNCHRONOUS, "1"), |
| 5303 | |
| 5304 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5305 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5306 | MockRead(SYNCHRONOUS, "22"), |
| 5307 | }; |
| 5308 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5309 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5311 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5313 | |
| 5314 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5315 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5316 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5317 | |
| 5318 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5320 | |
| 5321 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | |
| 5324 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5325 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5326 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5327 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5328 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5329 | |
| 5330 | LoadTimingInfo load_timing_info1; |
| 5331 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5332 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5333 | |
| 5334 | trans1.reset(); |
| 5335 | |
| 5336 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5337 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5339 | |
| 5340 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5342 | |
| 5343 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5344 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5345 | |
| 5346 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5347 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5348 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5349 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5350 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5351 | |
| 5352 | LoadTimingInfo load_timing_info2; |
| 5353 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5354 | TestLoadTimingReused(load_timing_info2); |
| 5355 | |
| 5356 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5357 | |
| 5358 | trans2.reset(); |
| 5359 | session->CloseAllConnections(); |
| 5360 | } |
| 5361 | |
| 5362 | // 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] | 5363 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5364 | HttpRequestInfo request1; |
| 5365 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5366 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5367 | request1.traffic_annotation = |
| 5368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5369 | |
| 5370 | HttpRequestInfo request2; |
| 5371 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5372 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5373 | request2.traffic_annotation = |
| 5374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5375 | |
| 5376 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5377 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5378 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5379 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5380 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5381 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5382 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5383 | |
| 5384 | // Since we have proxy, should try to establish tunnel. |
| 5385 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5386 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5387 | "Host: www.example.org:443\r\n" |
| 5388 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5389 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5390 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5391 | "Host: www.example.org\r\n" |
| 5392 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5393 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5394 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5395 | "Host: www.example.org\r\n" |
| 5396 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5397 | }; |
| 5398 | |
| 5399 | // The proxy responds to the connect with a 407, using a persistent |
| 5400 | // connection. |
| 5401 | MockRead data_reads1[] = { |
| 5402 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5403 | |
| 5404 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5405 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5406 | MockRead(SYNCHRONOUS, "1"), |
| 5407 | |
| 5408 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5409 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5410 | MockRead(SYNCHRONOUS, "22"), |
| 5411 | }; |
| 5412 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5413 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5415 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5417 | |
| 5418 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5419 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5420 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5421 | |
| 5422 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5424 | |
| 5425 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5427 | |
| 5428 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5429 | ASSERT_TRUE(response1); |
| 5430 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5431 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5432 | |
| 5433 | LoadTimingInfo load_timing_info1; |
| 5434 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5435 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5436 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5437 | |
| 5438 | trans1.reset(); |
| 5439 | |
| 5440 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5441 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5442 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5443 | |
| 5444 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5446 | |
| 5447 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5448 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5449 | |
| 5450 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5451 | ASSERT_TRUE(response2); |
| 5452 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5453 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5454 | |
| 5455 | LoadTimingInfo load_timing_info2; |
| 5456 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5457 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5458 | |
| 5459 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5460 | |
| 5461 | trans2.reset(); |
| 5462 | session->CloseAllConnections(); |
| 5463 | } |
| 5464 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5465 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5466 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5467 | HttpRequestInfo request; |
| 5468 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5469 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5470 | request.traffic_annotation = |
| 5471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5472 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5473 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5474 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5475 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5476 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5477 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5479 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5480 | // Since we have proxy, should use full url |
| 5481 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5482 | MockWrite( |
| 5483 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5484 | "Host: www.example.org\r\n" |
| 5485 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5486 | }; |
| 5487 | |
| 5488 | MockRead data_reads1[] = { |
| 5489 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5490 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5491 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5492 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5493 | }; |
| 5494 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5495 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5497 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5500 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5504 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5506 | |
| 5507 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5508 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5509 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5510 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5511 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5512 | TestLoadTimingNotReused(load_timing_info, |
| 5513 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5515 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5516 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5517 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5518 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5519 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5520 | EXPECT_EQ(200, response->headers->response_code()); |
| 5521 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5522 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5523 | |
| 5524 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5525 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5526 | } |
| 5527 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5528 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5529 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5530 | HttpRequestInfo request; |
| 5531 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5532 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5533 | request.traffic_annotation = |
| 5534 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5535 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5536 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5537 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5538 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5539 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5540 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5541 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5542 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5543 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5544 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5545 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5546 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5547 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5548 | spdy::SpdySerializedFrame resp( |
| 5549 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5550 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5551 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5552 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5553 | }; |
| 5554 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5555 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5556 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5557 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5558 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5559 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5561 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5562 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5564 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5566 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5568 | |
| 5569 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5570 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5571 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5572 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5573 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5574 | TestLoadTimingNotReused(load_timing_info, |
| 5575 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5576 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5577 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5578 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5579 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5580 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5581 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5582 | |
| 5583 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5584 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5585 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5586 | } |
| 5587 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5588 | // Verifies that a session which races and wins against the owning transaction |
| 5589 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5590 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5591 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5592 | HttpRequestInfo request; |
| 5593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5594 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5595 | request.traffic_annotation = |
| 5596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5597 | |
| 5598 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5599 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5600 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5601 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5602 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5604 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5605 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5606 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5607 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5608 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5609 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5610 | spdy::SpdySerializedFrame resp( |
| 5611 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5612 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5613 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5614 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5615 | }; |
| 5616 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5617 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5618 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5619 | |
| 5620 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5621 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5623 | |
| 5624 | TestCompletionCallback callback1; |
| 5625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5627 | |
| 5628 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5629 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5631 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5633 | |
| 5634 | // Race a session to the proxy, which completes first. |
| 5635 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5636 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5637 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 5638 | SpdySessionKey::IsProxySession::kTrue, SocketTag(), |
| 5639 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5640 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5641 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5642 | |
| 5643 | // Unstall the resolution begun by the transaction. |
| 5644 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5645 | session_deps_.host_resolver->ResolveAllPending(); |
| 5646 | |
| 5647 | EXPECT_FALSE(callback1.have_result()); |
| 5648 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5649 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5652 | ASSERT_TRUE(response); |
| 5653 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5654 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5655 | |
| 5656 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5657 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5658 | EXPECT_EQ(kUploadData, response_data); |
| 5659 | } |
| 5660 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5661 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5662 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5663 | HttpRequestInfo request; |
| 5664 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5665 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5666 | request.traffic_annotation = |
| 5667 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5668 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5669 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5670 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5671 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5672 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5673 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5675 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5676 | // The first request will be a bare GET, the second request will be a |
| 5677 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5678 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5679 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5680 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5681 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5682 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5683 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5684 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5685 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5686 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5687 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5688 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5689 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5690 | }; |
| 5691 | |
| 5692 | // The first response is a 407 proxy authentication challenge, and the second |
| 5693 | // response will be a 200 response since the second request includes a valid |
| 5694 | // Authorization header. |
| 5695 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5696 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5697 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5698 | spdy::SpdySerializedFrame resp_authentication( |
| 5699 | spdy_util_.ConstructSpdyReplyError( |
| 5700 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5701 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5702 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5703 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5704 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5705 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5706 | spdy::SpdySerializedFrame body_data( |
| 5707 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5708 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5709 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5710 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5711 | CreateMockRead(resp_data, 4), |
| 5712 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5713 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5714 | }; |
| 5715 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5716 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5718 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5719 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5720 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5723 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5725 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5727 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5729 | |
| 5730 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5733 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5734 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5735 | ASSERT_TRUE(response); |
| 5736 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5737 | EXPECT_EQ(407, response->headers->response_code()); |
| 5738 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5739 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5741 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5743 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5745 | |
| 5746 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5749 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5750 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5751 | ASSERT_TRUE(response_restart); |
| 5752 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5753 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5754 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5755 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5756 | } |
| 5757 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5758 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5759 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5760 | HttpRequestInfo request; |
| 5761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5762 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5763 | request.traffic_annotation = |
| 5764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5765 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5766 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5767 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5768 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5769 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5770 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5774 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5775 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5776 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5777 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5778 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5779 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5780 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5781 | const char get[] = |
| 5782 | "GET / HTTP/1.1\r\n" |
| 5783 | "Host: www.example.org\r\n" |
| 5784 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5785 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5786 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5787 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5788 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5789 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5790 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5791 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5792 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5793 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5794 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5795 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5796 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5797 | |
| 5798 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5799 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5800 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5801 | }; |
| 5802 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5803 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5804 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5805 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5806 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5807 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5808 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | }; |
| 5810 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5811 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5812 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5813 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5814 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5815 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5816 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5817 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5820 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5822 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5824 | |
| 5825 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5826 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5827 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5828 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5830 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5832 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5833 | ASSERT_TRUE(response); |
| 5834 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5835 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5836 | |
| 5837 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5838 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5839 | EXPECT_EQ("1234567890", response_data); |
| 5840 | } |
| 5841 | |
| 5842 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5843 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5844 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5845 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5846 | HttpRequestInfo request; |
| 5847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5848 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5849 | request.traffic_annotation = |
| 5850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5851 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5852 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5853 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5854 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5855 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5856 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5858 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5860 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5861 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5862 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5863 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5864 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5865 | // fetch https://www.example.org/ via SPDY |
| 5866 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5867 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5868 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5869 | spdy::SpdySerializedFrame wrapped_get( |
| 5870 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5871 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5872 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5873 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5874 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5875 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5876 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5877 | spdy::SpdySerializedFrame body( |
| 5878 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5879 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5880 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5881 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5882 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5883 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5884 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5885 | |
| 5886 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5887 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5888 | CreateMockWrite(window_update_get_resp, 6), |
| 5889 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5890 | }; |
| 5891 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5892 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5893 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5894 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5895 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5896 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5897 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5898 | }; |
| 5899 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5900 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5901 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5902 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5903 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5904 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5906 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5907 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5910 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5912 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5914 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5915 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5916 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5917 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5918 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5919 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5921 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5922 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5923 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5924 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5926 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5927 | ASSERT_TRUE(response); |
| 5928 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5929 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5930 | |
| 5931 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5932 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5933 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5937 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5938 | HttpRequestInfo request; |
| 5939 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5940 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5941 | request.traffic_annotation = |
| 5942 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5943 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5944 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5945 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5946 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5947 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5948 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5952 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5953 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5954 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5955 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5956 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5957 | spdy::SpdySerializedFrame get( |
| 5958 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5959 | |
| 5960 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5961 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5962 | }; |
| 5963 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5964 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5965 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5966 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5967 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5968 | }; |
| 5969 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5970 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5971 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5972 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5973 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5974 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5976 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5977 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5980 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5981 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5982 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5984 | |
| 5985 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5986 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5987 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5988 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5989 | } |
| 5990 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5991 | // 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] | 5992 | // is observed, but does exist by the time auth credentials are provided. In |
| 5993 | // this case, auth and SSL are fully negotated on the second request, but then |
| 5994 | // the socket is discarded to use the shared session. |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5995 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5996 | ProxyConfig proxy_config; |
| 5997 | proxy_config.set_auto_detect(true); |
| 5998 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5999 | |
| 6000 | CapturingProxyResolver capturing_proxy_resolver; |
| 6001 | capturing_proxy_resolver.set_proxy_server( |
| 6002 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 6003 | session_deps_.proxy_resolution_service = |
| 6004 | std::make_unique<ProxyResolutionService>( |
| 6005 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6006 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6007 | std::make_unique<CapturingProxyResolverFactory>( |
| 6008 | &capturing_proxy_resolver), |
| 6009 | nullptr); |
| 6010 | |
| 6011 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6012 | |
| 6013 | const char kMyUrl[] = "https://www.example.org/"; |
| 6014 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6015 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6016 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6017 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 6018 | |
| 6019 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6020 | spdy::SpdySerializedFrame get2( |
| 6021 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 6022 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6023 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6024 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 6025 | |
| 6026 | MockWrite auth_challenge_writes[] = { |
| 6027 | MockWrite(ASYNC, 0, |
| 6028 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6029 | "Host: www.example.org:443\r\n" |
| 6030 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6031 | MockWrite(ASYNC, 2, |
| 6032 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6033 | "Host: www.example.org:443\r\n" |
| 6034 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6035 | }; |
| 6036 | |
| 6037 | MockRead auth_challenge_reads[] = { |
| 6038 | MockRead(ASYNC, 1, |
| 6039 | "HTTP/1.1 407 Authentication Required\r\n" |
| 6040 | "Content-Length: 0\r\n" |
| 6041 | "Proxy-Connection: close\r\n" |
| 6042 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 6043 | }; |
| 6044 | |
| 6045 | MockWrite spdy_writes[] = { |
| 6046 | MockWrite(ASYNC, 0, |
| 6047 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6048 | "Host: www.example.org:443\r\n" |
| 6049 | "Proxy-Connection: keep-alive\r\n" |
| 6050 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6051 | CreateMockWrite(get, 2), |
| 6052 | CreateMockWrite(get2, 5), |
| 6053 | }; |
| 6054 | |
| 6055 | MockRead spdy_reads[] = { |
| 6056 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6057 | CreateMockRead(get_resp, 3, ASYNC), |
| 6058 | CreateMockRead(body, 4, ASYNC), |
| 6059 | CreateMockRead(get_resp2, 6, ASYNC), |
| 6060 | CreateMockRead(body2, 7, ASYNC), |
| 6061 | |
| 6062 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 6063 | }; |
| 6064 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6065 | MockWrite auth_response_writes_discarded_socket[] = { |
| 6066 | MockWrite(ASYNC, 0, |
| 6067 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6068 | "Host: www.example.org:443\r\n" |
| 6069 | "Proxy-Connection: keep-alive\r\n" |
| 6070 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 6071 | }; |
| 6072 | |
| 6073 | MockRead auth_response_reads_discarded_socket[] = { |
| 6074 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 6075 | }; |
| 6076 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6077 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 6078 | auth_challenge_writes); |
| 6079 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 6080 | |
| 6081 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 6082 | auth_challenge_writes); |
| 6083 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 6084 | |
| 6085 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 6086 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 6087 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6088 | SequencedSocketData auth_response_discarded_socket( |
| 6089 | auth_response_reads_discarded_socket, |
| 6090 | auth_response_writes_discarded_socket); |
| 6091 | session_deps_.socket_factory->AddSocketDataProvider( |
| 6092 | &auth_response_discarded_socket); |
| 6093 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6094 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6095 | ssl.next_proto = kProtoHTTP2; |
| 6096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6097 | |
Matt Menke | 5062be2 | 2019-05-01 17:50:24 | [diff] [blame] | 6098 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6099 | ssl2.next_proto = kProtoHTTP2; |
| 6100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6101 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6102 | TestCompletionCallback callback; |
| 6103 | std::string response_data; |
| 6104 | |
| 6105 | // Run first request until an auth challenge is observed. |
| 6106 | HttpRequestInfo request1; |
| 6107 | request1.method = "GET"; |
| 6108 | request1.url = GURL(kMyUrl); |
| 6109 | request1.traffic_annotation = |
| 6110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6111 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6112 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6113 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6114 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6115 | ASSERT_TRUE(response); |
| 6116 | ASSERT_TRUE(response->headers); |
| 6117 | EXPECT_EQ(407, response->headers->response_code()); |
| 6118 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6119 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6120 | |
| 6121 | // Run second request until an auth challenge is observed. |
| 6122 | HttpRequestInfo request2; |
| 6123 | request2.method = "GET"; |
| 6124 | request2.url = GURL(kMyUrl); |
| 6125 | request2.traffic_annotation = |
| 6126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6127 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6128 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6129 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6130 | response = trans2.GetResponseInfo(); |
| 6131 | ASSERT_TRUE(response); |
| 6132 | ASSERT_TRUE(response->headers); |
| 6133 | EXPECT_EQ(407, response->headers->response_code()); |
| 6134 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6135 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6136 | |
| 6137 | // Now provide credentials for the first request, and wait for it to complete. |
| 6138 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6139 | rv = callback.GetResult(rv); |
| 6140 | EXPECT_THAT(rv, IsOk()); |
| 6141 | response = trans1.GetResponseInfo(); |
| 6142 | ASSERT_TRUE(response); |
| 6143 | ASSERT_TRUE(response->headers); |
| 6144 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6145 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6146 | EXPECT_EQ(kUploadData, response_data); |
| 6147 | |
| 6148 | // Now provide credentials for the second request. It should notice the |
| 6149 | // existing session, and reuse it. |
| 6150 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6151 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6152 | response = trans2.GetResponseInfo(); |
| 6153 | ASSERT_TRUE(response); |
| 6154 | ASSERT_TRUE(response->headers); |
| 6155 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6156 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6157 | EXPECT_EQ(kUploadData, response_data); |
| 6158 | } |
| 6159 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6160 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6161 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6162 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6163 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6164 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6165 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6166 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6167 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6168 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6169 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6170 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6171 | |
| 6172 | HttpRequestInfo request1; |
| 6173 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6174 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6175 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6176 | request1.traffic_annotation = |
| 6177 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6178 | |
| 6179 | HttpRequestInfo request2; |
| 6180 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6181 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6183 | request2.traffic_annotation = |
| 6184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6186 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6187 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6188 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6189 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6190 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6191 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6192 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6193 | // Fetch https://www.example.org/ via HTTP. |
| 6194 | const char get1[] = |
| 6195 | "GET / HTTP/1.1\r\n" |
| 6196 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6197 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6198 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6199 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6200 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6201 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6202 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6203 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6204 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6205 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6206 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6207 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6208 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6209 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6210 | spdy::SpdyHeaderBlock connect2_block; |
| 6211 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6212 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6213 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6214 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6215 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6216 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6217 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6218 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6220 | // Fetch https://mail.example.org/ via HTTP. |
| 6221 | const char get2[] = |
| 6222 | "GET / HTTP/1.1\r\n" |
| 6223 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6224 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6225 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6226 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6227 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6228 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6229 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6230 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6231 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6232 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6233 | |
| 6234 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6235 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6236 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6237 | }; |
| 6238 | |
| 6239 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6240 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6241 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6242 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6243 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6244 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6245 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6246 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6247 | }; |
| 6248 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6249 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6250 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6251 | |
| 6252 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6253 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6255 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6257 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6259 | |
| 6260 | TestCompletionCallback callback; |
| 6261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6263 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6264 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6265 | |
| 6266 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6267 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6270 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6271 | ASSERT_TRUE(response); |
| 6272 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6273 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6274 | |
| 6275 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6276 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6277 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6278 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6280 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6281 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6282 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6283 | |
| 6284 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6285 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6286 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6287 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6288 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6289 | |
| 6290 | // The requests should have different IDs, since they each are using their own |
| 6291 | // separate stream. |
| 6292 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6294 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6295 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6296 | } |
| 6297 | |
| 6298 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6299 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6300 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6301 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6302 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6303 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6304 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6305 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6306 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6307 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6308 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6309 | |
| 6310 | HttpRequestInfo request1; |
| 6311 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6312 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6313 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6314 | request1.traffic_annotation = |
| 6315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6316 | |
| 6317 | HttpRequestInfo request2; |
| 6318 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6319 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6320 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6321 | request2.traffic_annotation = |
| 6322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6323 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6324 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6325 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6326 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6327 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6328 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6329 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6330 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6331 | // Fetch https://www.example.org/ via HTTP. |
| 6332 | const char get1[] = |
| 6333 | "GET / HTTP/1.1\r\n" |
| 6334 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6335 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6336 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6337 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6338 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6339 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6340 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6341 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6342 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6343 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6344 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6345 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6346 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6347 | // Fetch https://www.example.org/2 via HTTP. |
| 6348 | const char get2[] = |
| 6349 | "GET /2 HTTP/1.1\r\n" |
| 6350 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6351 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6352 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6353 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6354 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6355 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6356 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6357 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6358 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6359 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6360 | |
| 6361 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6362 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6363 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6364 | }; |
| 6365 | |
| 6366 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6367 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6368 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6369 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6370 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6371 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6372 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6373 | }; |
| 6374 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6375 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6376 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6377 | |
| 6378 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6379 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6381 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6383 | |
| 6384 | TestCompletionCallback callback; |
| 6385 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6386 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6387 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6388 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6390 | |
| 6391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6393 | |
| 6394 | LoadTimingInfo load_timing_info; |
| 6395 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6396 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6397 | |
| 6398 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6399 | ASSERT_TRUE(response); |
| 6400 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6401 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6402 | |
| 6403 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6404 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6405 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6406 | trans.reset(); |
| 6407 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6408 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6409 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6410 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6412 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6413 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6415 | |
| 6416 | LoadTimingInfo load_timing_info2; |
| 6417 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6418 | TestLoadTimingReused(load_timing_info2); |
| 6419 | |
| 6420 | // The requests should have the same ID. |
| 6421 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6422 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6423 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6427 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6428 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6429 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6430 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6431 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6432 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6433 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6434 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6435 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6436 | |
| 6437 | HttpRequestInfo request1; |
| 6438 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6439 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6440 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6441 | request1.traffic_annotation = |
| 6442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6443 | |
| 6444 | HttpRequestInfo request2; |
| 6445 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6446 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6447 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6448 | request2.traffic_annotation = |
| 6449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6450 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6451 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6452 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6453 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6454 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6455 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6456 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6457 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6458 | spdy::SpdySerializedFrame body1( |
| 6459 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6460 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6461 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6462 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6463 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6464 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6465 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6466 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6467 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6468 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6469 | spdy::SpdySerializedFrame body2( |
| 6470 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6471 | |
| 6472 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6473 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6474 | }; |
| 6475 | |
| 6476 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6477 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6478 | CreateMockRead(body1, 2, ASYNC), |
| 6479 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6480 | CreateMockRead(body2, 5, ASYNC), |
| 6481 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6482 | }; |
| 6483 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6484 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6485 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6486 | |
| 6487 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6488 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6490 | |
| 6491 | TestCompletionCallback callback; |
| 6492 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6493 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6494 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6495 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6496 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6497 | |
| 6498 | LoadTimingInfo load_timing_info; |
| 6499 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6500 | TestLoadTimingNotReused(load_timing_info, |
| 6501 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6502 | |
| 6503 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6504 | ASSERT_TRUE(response); |
| 6505 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6506 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6507 | |
| 6508 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6509 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6510 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6511 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6512 | // Delete the first request, so the second one can reuse the socket. |
| 6513 | trans.reset(); |
| 6514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6515 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6516 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6517 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6518 | |
| 6519 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6520 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6521 | TestLoadTimingReused(load_timing_info2); |
| 6522 | |
| 6523 | // The requests should have the same ID. |
| 6524 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6526 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6527 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6528 | } |
| 6529 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6530 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6531 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6532 | // would break socket pool isolation. |
| 6533 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6534 | ProxyConfig proxy_config; |
| 6535 | proxy_config.set_auto_detect(true); |
| 6536 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6537 | |
| 6538 | CapturingProxyResolver capturing_proxy_resolver; |
| 6539 | session_deps_.proxy_resolution_service = |
| 6540 | std::make_unique<ProxyResolutionService>( |
| 6541 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6542 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6543 | std::make_unique<CapturingProxyResolverFactory>( |
| 6544 | &capturing_proxy_resolver), |
| 6545 | nullptr); |
| 6546 | |
| 6547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6548 | |
| 6549 | SpdyTestUtil spdy_util1; |
| 6550 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6551 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6552 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6553 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6554 | // fetch https://www.example.org/ via HTTP/2. |
| 6555 | const char kMyUrl[] = "https://www.example.org/"; |
| 6556 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6557 | spdy::SpdySerializedFrame wrapped_get( |
| 6558 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6559 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6560 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6561 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6562 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6563 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6564 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6565 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6566 | spdy::SpdySerializedFrame wrapped_body( |
| 6567 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6568 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6569 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6570 | spdy::SpdySerializedFrame window_update_body( |
| 6571 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6572 | |
| 6573 | MockWrite spdy_writes1[] = { |
| 6574 | CreateMockWrite(connect, 0), |
| 6575 | CreateMockWrite(wrapped_get, 2), |
| 6576 | CreateMockWrite(window_update_get_resp, 6), |
| 6577 | CreateMockWrite(window_update_body, 7), |
| 6578 | }; |
| 6579 | |
| 6580 | MockRead spdy_reads1[] = { |
| 6581 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6582 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6583 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6584 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6585 | MockRead(ASYNC, 0, 8), |
| 6586 | }; |
| 6587 | |
| 6588 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6589 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6590 | |
| 6591 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6592 | // a new pipe. |
| 6593 | SpdyTestUtil spdy_util2; |
| 6594 | spdy::SpdySerializedFrame req( |
| 6595 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6596 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6597 | |
| 6598 | spdy::SpdySerializedFrame resp( |
| 6599 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6600 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6601 | MockRead spdy_reads2[] = { |
| 6602 | CreateMockRead(resp, 1), |
| 6603 | CreateMockRead(data, 2), |
| 6604 | MockRead(ASYNC, 0, 3), |
| 6605 | }; |
| 6606 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6607 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6608 | |
| 6609 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6610 | ssl.next_proto = kProtoHTTP2; |
| 6611 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6612 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6613 | ssl2.next_proto = kProtoHTTP2; |
| 6614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6615 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6616 | ssl3.next_proto = kProtoHTTP2; |
| 6617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6618 | |
| 6619 | TestCompletionCallback callback; |
| 6620 | std::string response_data; |
| 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 request1; |
| 6626 | request1.method = "GET"; |
| 6627 | request1.url = GURL("https://www.example.org/"); |
| 6628 | request1.traffic_annotation = |
| 6629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6630 | |
| 6631 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6632 | int rv = trans1.Start(&request1, 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_data1.Resume(); |
| 6639 | rv = callback.WaitForResult(); |
| 6640 | EXPECT_THAT(rv, IsOk()); |
| 6641 | |
| 6642 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6643 | ASSERT_TRUE(response); |
| 6644 | ASSERT_TRUE(response->headers); |
| 6645 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6646 | |
| 6647 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6648 | EXPECT_EQ(kUploadData, response_data); |
| 6649 | RunUntilIdle(); |
| 6650 | |
| 6651 | // Make a direct HTTP/2 request to proxy:70. |
| 6652 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6653 | HttpRequestInfo request2; |
| 6654 | request2.method = "GET"; |
| 6655 | request2.url = GURL("https://proxy:70/"); |
| 6656 | request2.traffic_annotation = |
| 6657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6658 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6659 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6660 | NetLogWithSource())), |
| 6661 | IsOk()); |
| 6662 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6663 | } |
| 6664 | |
| 6665 | // Same as above, but reverse request order, since the code to check for an |
| 6666 | // existing session is different for tunnels and direct connections. |
| 6667 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6668 | // Configure against https proxy server "myproxy:80". |
| 6669 | ProxyConfig proxy_config; |
| 6670 | proxy_config.set_auto_detect(true); |
| 6671 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6672 | |
| 6673 | CapturingProxyResolver capturing_proxy_resolver; |
| 6674 | session_deps_.proxy_resolution_service = |
| 6675 | std::make_unique<ProxyResolutionService>( |
| 6676 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6677 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6678 | std::make_unique<CapturingProxyResolverFactory>( |
| 6679 | &capturing_proxy_resolver), |
| 6680 | nullptr); |
| 6681 | |
| 6682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6683 | // Fetch https://proxy:70/ via HTTP/2. |
| 6684 | SpdyTestUtil spdy_util1; |
| 6685 | spdy::SpdySerializedFrame req( |
| 6686 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6687 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6688 | |
| 6689 | spdy::SpdySerializedFrame resp( |
| 6690 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6691 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6692 | MockRead spdy_reads1[] = { |
| 6693 | CreateMockRead(resp, 1), |
| 6694 | CreateMockRead(data, 2), |
| 6695 | MockRead(ASYNC, 0, 3), |
| 6696 | }; |
| 6697 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6698 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6699 | |
| 6700 | SpdyTestUtil spdy_util2; |
| 6701 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6702 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6703 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6704 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6705 | // fetch https://www.example.org/ via HTTP/2. |
| 6706 | const char kMyUrl[] = "https://www.example.org/"; |
| 6707 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6708 | spdy::SpdySerializedFrame wrapped_get( |
| 6709 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6710 | spdy::SpdySerializedFrame conn_resp( |
| 6711 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6712 | spdy::SpdySerializedFrame get_resp( |
| 6713 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6714 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6715 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6716 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6717 | spdy::SpdySerializedFrame wrapped_body( |
| 6718 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6719 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6720 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6721 | spdy::SpdySerializedFrame window_update_body( |
| 6722 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6723 | |
| 6724 | MockWrite spdy_writes2[] = { |
| 6725 | CreateMockWrite(connect, 0), |
| 6726 | CreateMockWrite(wrapped_get, 2), |
| 6727 | CreateMockWrite(window_update_get_resp, 6), |
| 6728 | CreateMockWrite(window_update_body, 7), |
| 6729 | }; |
| 6730 | |
| 6731 | MockRead spdy_reads2[] = { |
| 6732 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6733 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6734 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6735 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6736 | MockRead(ASYNC, 0, 8), |
| 6737 | }; |
| 6738 | |
| 6739 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6740 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6741 | |
| 6742 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6743 | ssl.next_proto = kProtoHTTP2; |
| 6744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6745 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6746 | ssl2.next_proto = kProtoHTTP2; |
| 6747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6748 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6749 | ssl3.next_proto = kProtoHTTP2; |
| 6750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6751 | |
| 6752 | TestCompletionCallback callback; |
| 6753 | std::string response_data; |
| 6754 | |
| 6755 | // Make a direct HTTP/2 request to proxy:70. |
| 6756 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6757 | HttpRequestInfo request1; |
| 6758 | request1.method = "GET"; |
| 6759 | request1.url = GURL("https://proxy:70/"); |
| 6760 | request1.traffic_annotation = |
| 6761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6762 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6763 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6764 | NetLogWithSource())), |
| 6765 | IsOk()); |
| 6766 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6767 | RunUntilIdle(); |
| 6768 | |
| 6769 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6770 | capturing_proxy_resolver.set_proxy_server( |
| 6771 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6772 | HttpRequestInfo request2; |
| 6773 | request2.method = "GET"; |
| 6774 | request2.url = GURL("https://www.example.org/"); |
| 6775 | request2.traffic_annotation = |
| 6776 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6777 | |
| 6778 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6779 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6781 | |
| 6782 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6783 | base::RunLoop().RunUntilIdle(); |
| 6784 | // Now allow the read of the response to complete. |
| 6785 | spdy_data2.Resume(); |
| 6786 | rv = callback.WaitForResult(); |
| 6787 | EXPECT_THAT(rv, IsOk()); |
| 6788 | |
| 6789 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6790 | ASSERT_TRUE(response2); |
| 6791 | ASSERT_TRUE(response2->headers); |
| 6792 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6793 | |
| 6794 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6795 | EXPECT_EQ(kUploadData, response_data); |
| 6796 | } |
| 6797 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6798 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6799 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6800 | HttpRequestInfo request; |
| 6801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6802 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6803 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6804 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6805 | request.traffic_annotation = |
| 6806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6807 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6808 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6809 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6810 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6811 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6812 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6814 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6815 | // Since we have proxy, should use full url |
| 6816 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6817 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6818 | "Host: www.example.org\r\n" |
| 6819 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6821 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6822 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6823 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6824 | "Host: www.example.org\r\n" |
| 6825 | "Proxy-Connection: keep-alive\r\n" |
| 6826 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6827 | }; |
| 6828 | |
| 6829 | // The proxy responds to the GET with a 407, using a persistent |
| 6830 | // connection. |
| 6831 | MockRead data_reads1[] = { |
| 6832 | // No credentials. |
| 6833 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6834 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6835 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6836 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6837 | |
| 6838 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6839 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6840 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6841 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6842 | }; |
| 6843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6844 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6845 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6846 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6847 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6848 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6849 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6851 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6853 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6855 | |
| 6856 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6857 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6858 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6859 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6860 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6861 | TestLoadTimingNotReused(load_timing_info, |
| 6862 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6865 | ASSERT_TRUE(response); |
| 6866 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6867 | EXPECT_EQ(407, response->headers->response_code()); |
| 6868 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6869 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6870 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6872 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6874 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6876 | |
| 6877 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6878 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6879 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6880 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6881 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6882 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6883 | TestLoadTimingReused(load_timing_info); |
| 6884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6885 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6886 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6887 | |
| 6888 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6889 | EXPECT_EQ(200, response->headers->response_code()); |
| 6890 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6891 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6892 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6893 | |
| 6894 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6895 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6896 | } |
| 6897 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6898 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6899 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6900 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6902 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6903 | request.traffic_annotation = |
| 6904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6906 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6907 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6908 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6910 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6911 | // Since we have proxy, should try to establish tunnel. |
| 6912 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6913 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6914 | "Host: www.example.org:443\r\n" |
| 6915 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6916 | }; |
| 6917 | |
| 6918 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6919 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6920 | // No response body because the test stops reading here. |
| 6921 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6922 | }; |
| 6923 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6924 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6925 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6927 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6929 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6930 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 6931 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6933 | |
| 6934 | rv = callback.WaitForResult(); |
| 6935 | EXPECT_EQ(expected_status, rv); |
| 6936 | } |
| 6937 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6938 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6939 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6940 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6941 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6942 | } |
| 6943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6944 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6945 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6946 | } |
| 6947 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6948 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6949 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6950 | } |
| 6951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6952 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6953 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6954 | } |
| 6955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6956 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6957 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6958 | } |
| 6959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6961 | ConnectStatusHelper( |
| 6962 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6963 | } |
| 6964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6965 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6966 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6967 | } |
| 6968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6969 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6970 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6971 | } |
| 6972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6973 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6974 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6975 | } |
| 6976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6977 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6978 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6979 | } |
| 6980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6981 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6982 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6983 | } |
| 6984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6985 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6986 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6987 | } |
| 6988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6989 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6990 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6991 | } |
| 6992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6993 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6994 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6995 | } |
| 6996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6997 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6998 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6999 | } |
| 7000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7001 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7002 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 7003 | } |
| 7004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7005 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7006 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 7007 | } |
| 7008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7009 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 7010 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 7011 | } |
| 7012 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7013 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7014 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 7015 | } |
| 7016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7017 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7018 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 7019 | } |
| 7020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7021 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7022 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 7023 | } |
| 7024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7025 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7026 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 7027 | } |
| 7028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7029 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7030 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 7031 | } |
| 7032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7033 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7034 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 7035 | } |
| 7036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7037 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7038 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 7039 | } |
| 7040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7041 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7042 | ConnectStatusHelperWithExpectedStatus( |
| 7043 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 7044 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7045 | } |
| 7046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7047 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7048 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 7049 | } |
| 7050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7051 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7052 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 7053 | } |
| 7054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7055 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7056 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 7057 | } |
| 7058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7059 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7060 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 7061 | } |
| 7062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7063 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7064 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 7065 | } |
| 7066 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7067 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7068 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 7069 | } |
| 7070 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7071 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7072 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 7073 | } |
| 7074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7075 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7076 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 7077 | } |
| 7078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7079 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7080 | ConnectStatusHelper( |
| 7081 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 7082 | } |
| 7083 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7084 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7085 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 7086 | } |
| 7087 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7088 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7089 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 7090 | } |
| 7091 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7092 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7093 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 7094 | } |
| 7095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7096 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7097 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 7098 | } |
| 7099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7100 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7101 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 7102 | } |
| 7103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7104 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7105 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 7106 | } |
| 7107 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7108 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7109 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 7110 | } |
| 7111 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7112 | // Test the flow when both the proxy server AND origin server require |
| 7113 | // authentication. Again, this uses basic auth for both since that is |
| 7114 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7115 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7116 | HttpRequestInfo request; |
| 7117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7118 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7119 | request.traffic_annotation = |
| 7120 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7121 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7122 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7123 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7124 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7126 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7127 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7128 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7129 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7130 | MockWrite( |
| 7131 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7132 | "Host: www.example.org\r\n" |
| 7133 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7134 | }; |
| 7135 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7136 | MockRead data_reads1[] = { |
| 7137 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7138 | // Give a couple authenticate options (only the middle one is actually |
| 7139 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7140 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7141 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7142 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7143 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7144 | // Large content-length -- won't matter, as connection will be reset. |
| 7145 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7146 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7147 | }; |
| 7148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7149 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7150 | // request we should be issuing -- the final header line contains the |
| 7151 | // proxy's credentials. |
| 7152 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7153 | MockWrite( |
| 7154 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7155 | "Host: www.example.org\r\n" |
| 7156 | "Proxy-Connection: keep-alive\r\n" |
| 7157 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7158 | }; |
| 7159 | |
| 7160 | // Now the proxy server lets the request pass through to origin server. |
| 7161 | // The origin server responds with a 401. |
| 7162 | MockRead data_reads2[] = { |
| 7163 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7164 | // Note: We are using the same realm-name as the proxy server. This is |
| 7165 | // completely valid, as realms are unique across hosts. |
| 7166 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7167 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7168 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7169 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7170 | }; |
| 7171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7172 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7173 | // the credentials for both the proxy and origin server. |
| 7174 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7175 | MockWrite( |
| 7176 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7177 | "Host: www.example.org\r\n" |
| 7178 | "Proxy-Connection: keep-alive\r\n" |
| 7179 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7180 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7181 | }; |
| 7182 | |
| 7183 | // Lastly we get the desired content. |
| 7184 | MockRead data_reads3[] = { |
| 7185 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7186 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7187 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7188 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7189 | }; |
| 7190 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7191 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7192 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7193 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7195 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7196 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7198 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7199 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7200 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7202 | |
| 7203 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7204 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7206 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7207 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7208 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7210 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7212 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7213 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7214 | |
| 7215 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7217 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7218 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7219 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7220 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7221 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7222 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7224 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7225 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7227 | |
| 7228 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7229 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7231 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7232 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7233 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7234 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7235 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7236 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7237 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7238 | // authorization headers. |
| 7239 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7240 | // The NTLM authentication unit tests are based on known test data from the |
| 7241 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7242 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7243 | // for the implementation and testing of the protocol. |
| 7244 | // |
| 7245 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7246 | |
| 7247 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7248 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7249 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7250 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7251 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7252 | request.traffic_annotation = |
| 7253 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7254 | |
| 7255 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7256 | // to other auth schemes. |
| 7257 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7258 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7259 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7260 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7262 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7263 | // Generate the NTLM messages based on known test data. |
| 7264 | std::string negotiate_msg; |
| 7265 | std::string challenge_msg; |
| 7266 | std::string authenticate_msg; |
| 7267 | base::Base64Encode( |
| 7268 | base::StringPiece( |
| 7269 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7270 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7271 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7272 | base::Base64Encode( |
| 7273 | base::StringPiece( |
| 7274 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7275 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7276 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7277 | base::Base64Encode( |
| 7278 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7279 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7280 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7281 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7282 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7283 | &authenticate_msg); |
| 7284 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7285 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7286 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7287 | "Host: server\r\n" |
| 7288 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7289 | }; |
| 7290 | |
| 7291 | MockRead data_reads1[] = { |
| 7292 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7293 | // Negotiate and NTLM are often requested together. However, we only want |
| 7294 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7295 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7296 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7297 | MockRead("Connection: close\r\n"), |
| 7298 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7299 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7300 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7301 | }; |
| 7302 | |
| 7303 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7304 | // After restarting with a null identity, this is the |
| 7305 | // request we should be issuing -- the final header line contains a Type |
| 7306 | // 1 message. |
| 7307 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7308 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7309 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7310 | "Authorization: NTLM "), |
| 7311 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7313 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7314 | // (using correct credentials). The second request continues on the |
| 7315 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7316 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7317 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7318 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7319 | "Authorization: NTLM "), |
| 7320 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7321 | }; |
| 7322 | |
| 7323 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7324 | // The origin server responds with a Type 2 message. |
| 7325 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7326 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7327 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7328 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7329 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7330 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7331 | // Lastly we get the desired content. |
| 7332 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7333 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7334 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7335 | }; |
| 7336 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7337 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7338 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7339 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7340 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7341 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7342 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7344 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7347 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7348 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7349 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7350 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7351 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7352 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7353 | |
| 7354 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7355 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7357 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7360 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7361 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7363 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7364 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7365 | rv = trans.RestartWithAuth( |
| 7366 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7367 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7369 | |
| 7370 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7373 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7375 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7376 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7377 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7379 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7381 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7383 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7384 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7388 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7389 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7390 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7391 | |
| 7392 | std::string response_data; |
| 7393 | rv = ReadTransaction(&trans, &response_data); |
| 7394 | EXPECT_THAT(rv, IsOk()); |
| 7395 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7396 | |
| 7397 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7398 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7399 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7400 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7401 | } |
| 7402 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7403 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7404 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7405 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7406 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7407 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7408 | request.traffic_annotation = |
| 7409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7410 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7411 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7412 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7414 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7415 | // Generate the NTLM messages based on known test data. |
| 7416 | std::string negotiate_msg; |
| 7417 | std::string challenge_msg; |
| 7418 | std::string authenticate_msg; |
| 7419 | base::Base64Encode( |
| 7420 | base::StringPiece( |
| 7421 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7422 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7423 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7424 | base::Base64Encode( |
| 7425 | base::StringPiece( |
| 7426 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7427 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7428 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7429 | base::Base64Encode( |
| 7430 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7431 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7432 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7433 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7434 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7435 | &authenticate_msg); |
| 7436 | |
| 7437 | // The authenticate message when |kWrongPassword| is sent. |
| 7438 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7439 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7440 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7441 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7442 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7443 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7444 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7445 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7446 | // Sanity check that it's the same length as the correct authenticate message |
| 7447 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7448 | ASSERT_EQ(authenticate_msg.length(), |
| 7449 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7450 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7451 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7452 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7453 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7454 | "Host: server\r\n" |
| 7455 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7456 | }; |
| 7457 | |
| 7458 | MockRead data_reads1[] = { |
| 7459 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7460 | // Negotiate and NTLM are often requested together. However, we only want |
| 7461 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7462 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7463 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7464 | MockRead("Connection: close\r\n"), |
| 7465 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7466 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7467 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7468 | }; |
| 7469 | |
| 7470 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7471 | // After restarting with a null identity, this is the |
| 7472 | // request we should be issuing -- the final header line contains a Type |
| 7473 | // 1 message. |
| 7474 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7475 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7476 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7477 | "Authorization: NTLM "), |
| 7478 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7481 | // (using incorrect credentials). The second request continues on the |
| 7482 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7483 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7484 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7486 | "Authorization: NTLM "), |
| 7487 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7488 | }; |
| 7489 | |
| 7490 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7491 | // The origin server responds with a Type 2 message. |
| 7492 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7493 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7494 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7495 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7496 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7497 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7498 | // Wrong password. |
| 7499 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7500 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7501 | MockRead("Content-Length: 42\r\n"), |
| 7502 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7503 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7504 | }; |
| 7505 | |
| 7506 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7507 | // After restarting with a null identity, this is the |
| 7508 | // request we should be issuing -- the final header line contains a Type |
| 7509 | // 1 message. |
| 7510 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7511 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7512 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7513 | "Authorization: NTLM "), |
| 7514 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7516 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7517 | // (the credentials for the origin server). The second request continues |
| 7518 | // on the same connection. |
| 7519 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7520 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7521 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7522 | "Authorization: NTLM "), |
| 7523 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7524 | }; |
| 7525 | |
| 7526 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7527 | // The origin server responds with a Type 2 message. |
| 7528 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7529 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7530 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7531 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7532 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7533 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7534 | // Lastly we get the desired content. |
| 7535 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7536 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7537 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7538 | }; |
| 7539 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7540 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7541 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7542 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7543 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7544 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7545 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7546 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7547 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7549 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7551 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7554 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7556 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7557 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 7558 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7560 | |
| 7561 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7562 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7564 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7566 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7567 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7568 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7570 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7571 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7572 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7573 | rv = trans.RestartWithAuth( |
| 7574 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7575 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7576 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7577 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7578 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7579 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7581 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7582 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7583 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7584 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7585 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7586 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7587 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7589 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7590 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7591 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7593 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7594 | |
| 7595 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7596 | rv = trans.RestartWithAuth( |
| 7597 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7598 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7600 | |
| 7601 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7604 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7606 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7607 | |
| 7608 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7609 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7611 | |
| 7612 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7613 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7615 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7616 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7617 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7618 | |
| 7619 | std::string response_data; |
| 7620 | rv = ReadTransaction(&trans, &response_data); |
| 7621 | EXPECT_THAT(rv, IsOk()); |
| 7622 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7623 | |
| 7624 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7625 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7626 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7627 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7628 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7629 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7630 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7631 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7632 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7633 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7634 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7635 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7636 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7637 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7638 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7639 | |
| 7640 | HttpRequestInfo request; |
| 7641 | request.method = "GET"; |
| 7642 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7643 | request.traffic_annotation = |
| 7644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7645 | |
| 7646 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7647 | spdy::SpdyHeaderBlock request_headers0( |
| 7648 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7649 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7650 | 1, std::move(request_headers0), LOWEST, true)); |
| 7651 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7652 | spdy::SpdyHeaderBlock response_headers0; |
| 7653 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7654 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7655 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7656 | 1, std::move(response_headers0), true)); |
| 7657 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7658 | // Stream 1 is closed. |
| 7659 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7660 | |
| 7661 | // Generate the NTLM messages based on known test data. |
| 7662 | std::string negotiate_msg; |
| 7663 | std::string challenge_msg; |
| 7664 | std::string authenticate_msg; |
| 7665 | base::Base64Encode( |
| 7666 | base::StringPiece( |
| 7667 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7668 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7669 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7670 | base::Base64Encode( |
| 7671 | base::StringPiece( |
| 7672 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7673 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7674 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7675 | base::Base64Encode( |
| 7676 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7677 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7678 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7679 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7680 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7681 | &authenticate_msg); |
| 7682 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7683 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7684 | MockRead reads0[] = {CreateMockRead(resp, 1), |
| 7685 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7686 | |
| 7687 | // Retry yet again using HTTP/1.1. |
| 7688 | MockWrite writes1[] = { |
| 7689 | // After restarting with a null identity, this is the |
| 7690 | // request we should be issuing -- the final header line contains a Type |
| 7691 | // 1 message. |
| 7692 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7693 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7694 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7695 | "Authorization: NTLM "), |
| 7696 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7697 | |
| 7698 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7699 | // (the credentials for the origin server). The second request continues |
| 7700 | // on the same connection. |
| 7701 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7702 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7703 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7704 | "Authorization: NTLM "), |
| 7705 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7706 | }; |
| 7707 | |
| 7708 | MockRead reads1[] = { |
| 7709 | // The origin server responds with a Type 2 message. |
| 7710 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7711 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7712 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7713 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7714 | MockRead("You are not authorized to view this page\r\n"), |
| 7715 | |
| 7716 | // Lastly we get the desired content. |
| 7717 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7718 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7719 | 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] | 7720 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7721 | SequencedSocketData data0(reads0, writes0); |
| 7722 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7723 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7725 | |
| 7726 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7727 | ssl0.next_proto = kProtoHTTP2; |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7728 | ssl0.next_protos_expected_in_ssl_config = |
| 7729 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7730 | SSLSocketDataProvider ssl1(ASYNC, OK); |
Matt Menke | 6082f95 | 2019-08-21 16:23:16 | [diff] [blame] | 7731 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 7732 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{kProtoHTTP11}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7734 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7735 | |
| 7736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7738 | |
| 7739 | TestCompletionCallback callback1; |
| 7740 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7742 | |
| 7743 | rv = callback1.WaitForResult(); |
| 7744 | EXPECT_THAT(rv, IsOk()); |
| 7745 | |
| 7746 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7747 | |
| 7748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7749 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7750 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7751 | |
| 7752 | TestCompletionCallback callback2; |
| 7753 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7754 | rv = trans.RestartWithAuth( |
| 7755 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7756 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7758 | |
| 7759 | rv = callback2.WaitForResult(); |
| 7760 | EXPECT_THAT(rv, IsOk()); |
| 7761 | |
| 7762 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7763 | |
| 7764 | response = trans.GetResponseInfo(); |
| 7765 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7766 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7767 | |
| 7768 | TestCompletionCallback callback3; |
| 7769 | |
| 7770 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7772 | |
| 7773 | rv = callback3.WaitForResult(); |
| 7774 | EXPECT_THAT(rv, IsOk()); |
| 7775 | |
| 7776 | response = trans.GetResponseInfo(); |
| 7777 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7778 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7779 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7780 | |
| 7781 | std::string response_data; |
| 7782 | rv = ReadTransaction(&trans, &response_data); |
| 7783 | EXPECT_THAT(rv, IsOk()); |
| 7784 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7785 | |
| 7786 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7787 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7788 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7789 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7790 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7791 | |
Matt Menke | f2ee07c | 2019-08-29 02:10:36 | [diff] [blame] | 7792 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 7793 | |
| 7794 | // Variant of above test using WebSockets. |
| 7795 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2WithWebsockets) { |
| 7796 | const GURL kInitialUrl("https://server/"); |
| 7797 | const GURL kWebSocketUrl("wss://server/"); |
| 7798 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7799 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7800 | |
| 7801 | // Initial request establishes an H2 connection, which will then be reused for |
| 7802 | // WebSockets. This is needed since WebSockets will reuse H2 connections, but |
| 7803 | // it won't create a new one. |
| 7804 | spdy::SpdyHeaderBlock initial_request_headers( |
| 7805 | spdy_util_.ConstructGetHeaderBlock(kInitialUrl.spec())); |
| 7806 | spdy::SpdySerializedFrame initial_request(spdy_util_.ConstructSpdyHeaders( |
| 7807 | 1, std::move(initial_request_headers), DEFAULT_PRIORITY, true)); |
| 7808 | spdy::SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 7809 | |
| 7810 | // Settings frame, indicating WebSockets is supported. |
| 7811 | spdy::SettingsMap settings; |
| 7812 | settings[spdy::SETTINGS_ENABLE_CONNECT_PROTOCOL] = 1; |
| 7813 | spdy::SpdySerializedFrame settings_frame( |
| 7814 | spdy_util_.ConstructSpdySettings(settings)); |
| 7815 | |
| 7816 | // Response headers for first request. Body is never received, but that |
| 7817 | // shouldn't matter for the purposes of this test. |
| 7818 | spdy::SpdySerializedFrame initial_response( |
| 7819 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 7820 | |
| 7821 | // First WebSocket request, which has no credentials. |
| 7822 | spdy::SpdyHeaderBlock websocket_request_headers; |
| 7823 | websocket_request_headers[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 7824 | websocket_request_headers[spdy::kHttp2AuthorityHeader] = "server"; |
| 7825 | websocket_request_headers[spdy::kHttp2SchemeHeader] = "https"; |
| 7826 | websocket_request_headers[spdy::kHttp2PathHeader] = "/"; |
| 7827 | websocket_request_headers[spdy::kHttp2ProtocolHeader] = "websocket"; |
| 7828 | websocket_request_headers["origin"] = "http://server"; |
| 7829 | websocket_request_headers["sec-websocket-version"] = "13"; |
| 7830 | websocket_request_headers["sec-websocket-extensions"] = |
| 7831 | "permessage-deflate; client_max_window_bits"; |
| 7832 | spdy::SpdySerializedFrame websocket_request(spdy_util_.ConstructSpdyHeaders( |
| 7833 | 3, std::move(websocket_request_headers), MEDIUM, false)); |
| 7834 | |
| 7835 | // Auth challenge to WebSocket request. |
| 7836 | spdy::SpdyHeaderBlock auth_challenge_headers; |
| 7837 | auth_challenge_headers[spdy::kHttp2StatusHeader] = "401"; |
| 7838 | auth_challenge_headers["www-authenticate"] = "NTLM"; |
| 7839 | spdy::SpdySerializedFrame websocket_auth_challenge( |
| 7840 | spdy_util_.ConstructSpdyResponseHeaders( |
| 7841 | 3, std::move(auth_challenge_headers), true)); |
| 7842 | |
| 7843 | MockWrite writes0[] = {CreateMockWrite(initial_request, 0), |
| 7844 | CreateMockWrite(settings_ack, 2), |
| 7845 | CreateMockWrite(websocket_request, 4), |
| 7846 | MockWrite(SYNCHRONOUS, ERR_IO_PENDING, 7)}; |
| 7847 | MockRead reads0[] = {CreateMockRead(settings_frame, 1), |
| 7848 | CreateMockRead(initial_response, 3), |
| 7849 | CreateMockRead(websocket_auth_challenge, 5), |
| 7850 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6)}; |
| 7851 | |
| 7852 | // Generate the NTLM messages based on known test data. |
| 7853 | std::string negotiate_msg; |
| 7854 | std::string challenge_msg; |
| 7855 | std::string authenticate_msg; |
| 7856 | base::Base64Encode( |
| 7857 | base::StringPiece( |
| 7858 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 7859 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
| 7860 | &negotiate_msg); |
| 7861 | base::Base64Encode( |
| 7862 | base::StringPiece( |
| 7863 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 7864 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
| 7865 | &challenge_msg); |
| 7866 | base::Base64Encode( |
| 7867 | base::StringPiece( |
| 7868 | reinterpret_cast<const char*>( |
| 7869 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 7870 | base::size( |
| 7871 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7872 | &authenticate_msg); |
| 7873 | |
| 7874 | // Retry yet again using HTTP/1.1. |
| 7875 | MockWrite writes1[] = { |
| 7876 | // After restarting with a null identity, this is the |
| 7877 | // request we should be issuing -- the final header line contains a Type |
| 7878 | // 1 message. |
| 7879 | MockWrite("GET / HTTP/1.1\r\n" |
| 7880 | "Host: server\r\n" |
| 7881 | "Connection: Upgrade\r\n" |
| 7882 | "Authorization: NTLM "), |
| 7883 | MockWrite(negotiate_msg.c_str()), |
| 7884 | MockWrite("\r\n"), |
| 7885 | MockWrite("Origin: http://server\r\n" |
| 7886 | "Sec-WebSocket-Version: 13\r\n" |
| 7887 | "Upgrade: websocket\r\n" |
| 7888 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 7889 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 7890 | "client_max_window_bits\r\n\r\n"), |
| 7891 | |
| 7892 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7893 | // (the credentials for the origin server). The second request continues |
| 7894 | // on the same connection. |
| 7895 | MockWrite("GET / HTTP/1.1\r\n" |
| 7896 | "Host: server\r\n" |
| 7897 | "Connection: Upgrade\r\n" |
| 7898 | "Authorization: NTLM "), |
| 7899 | MockWrite(authenticate_msg.c_str()), |
| 7900 | MockWrite("\r\n"), |
| 7901 | MockWrite("Origin: http://server\r\n" |
| 7902 | "Sec-WebSocket-Version: 13\r\n" |
| 7903 | "Upgrade: websocket\r\n" |
| 7904 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 7905 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 7906 | "client_max_window_bits\r\n\r\n"), |
| 7907 | }; |
| 7908 | |
| 7909 | MockRead reads1[] = { |
| 7910 | // The origin server responds with a Type 2 message. |
| 7911 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7912 | MockRead("WWW-Authenticate: NTLM "), |
| 7913 | MockRead(challenge_msg.c_str()), |
| 7914 | MockRead("\r\n"), |
| 7915 | MockRead("Content-Length: 42\r\n"), |
| 7916 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7917 | MockRead("You are not authorized to view this page\r\n"), |
| 7918 | |
| 7919 | // Lastly we get the desired content. |
| 7920 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 7921 | "Upgrade: websocket\r\n" |
| 7922 | "Connection: Upgrade\r\n" |
| 7923 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 7924 | }; |
| 7925 | SequencedSocketData data0(reads0, writes0); |
| 7926 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7927 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7928 | ssl0.next_proto = kProtoHTTP2; |
| 7929 | ssl0.next_protos_expected_in_ssl_config = |
| 7930 | NextProtoVector{kProtoHTTP2, kProtoHTTP11}; |
| 7931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7932 | |
| 7933 | StaticSocketDataProvider data1(reads1, writes1); |
| 7934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7935 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7936 | // When creating the second connection, only HTTP/1.1 should be allowed. |
| 7937 | ssl1.next_protos_expected_in_ssl_config = NextProtoVector{}; |
| 7938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7939 | |
| 7940 | session_deps_.enable_websocket_over_http2 = true; |
| 7941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7942 | |
| 7943 | HttpRequestInfo initial_request_info; |
| 7944 | initial_request_info.method = "GET"; |
| 7945 | initial_request_info.url = kInitialUrl; |
| 7946 | initial_request_info.traffic_annotation = |
| 7947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7948 | HttpNetworkTransaction initial_trans(DEFAULT_PRIORITY, session.get()); |
| 7949 | TestCompletionCallback initial_callback; |
| 7950 | int rv = initial_trans.Start(&initial_request_info, |
| 7951 | initial_callback.callback(), NetLogWithSource()); |
| 7952 | EXPECT_THAT(initial_callback.GetResult(rv), IsOk()); |
| 7953 | |
| 7954 | EXPECT_FALSE(session->http_server_properties()->RequiresHTTP11( |
| 7955 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 7956 | |
| 7957 | HttpRequestInfo websocket_request_info; |
| 7958 | websocket_request_info.method = "GET"; |
| 7959 | websocket_request_info.url = kWebSocketUrl; |
| 7960 | websocket_request_info.traffic_annotation = |
| 7961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7962 | EXPECT_TRUE(HostPortPair::FromURL(initial_request_info.url) |
| 7963 | .Equals(HostPortPair::FromURL(websocket_request_info.url))); |
| 7964 | websocket_request_info.extra_headers.SetHeader("Origin", "http://server"); |
| 7965 | websocket_request_info.extra_headers.SetHeader("Sec-WebSocket-Version", "13"); |
| 7966 | // The following two headers must be removed by WebSocketHttp2HandshakeStream. |
| 7967 | websocket_request_info.extra_headers.SetHeader("Connection", "Upgrade"); |
| 7968 | websocket_request_info.extra_headers.SetHeader("Upgrade", "websocket"); |
| 7969 | |
| 7970 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 7971 | |
| 7972 | HttpNetworkTransaction websocket_trans(MEDIUM, session.get()); |
| 7973 | websocket_trans.SetWebSocketHandshakeStreamCreateHelper( |
| 7974 | &websocket_stream_create_helper); |
| 7975 | |
| 7976 | TestCompletionCallback websocket_callback; |
| 7977 | rv = websocket_trans.Start(&websocket_request_info, |
| 7978 | websocket_callback.callback(), NetLogWithSource()); |
| 7979 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 7980 | |
| 7981 | EXPECT_FALSE(websocket_trans.IsReadyToRestartForAuth()); |
| 7982 | |
| 7983 | const HttpResponseInfo* response = websocket_trans.GetResponseInfo(); |
| 7984 | ASSERT_TRUE(response); |
| 7985 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
| 7986 | |
| 7987 | rv = websocket_trans.RestartWithAuth( |
| 7988 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7989 | websocket_callback.callback()); |
| 7990 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 7991 | |
| 7992 | EXPECT_TRUE(websocket_trans.IsReadyToRestartForAuth()); |
| 7993 | |
| 7994 | response = websocket_trans.GetResponseInfo(); |
| 7995 | ASSERT_TRUE(response); |
| 7996 | EXPECT_FALSE(response->auth_challenge.has_value()); |
| 7997 | |
| 7998 | rv = websocket_trans.RestartWithAuth(AuthCredentials(), |
| 7999 | websocket_callback.callback()); |
| 8000 | EXPECT_THAT(websocket_callback.GetResult(rv), IsOk()); |
| 8001 | |
| 8002 | // The server should have been marked as requiring HTTP/1.1. The important |
| 8003 | // part here is that the scheme that requires HTTP/1.1 should be HTTPS, not |
| 8004 | // WSS. |
| 8005 | EXPECT_TRUE(session->http_server_properties()->RequiresHTTP11( |
| 8006 | url::SchemeHostPort(kInitialUrl), NetworkIsolationKey())); |
| 8007 | } |
| 8008 | |
| 8009 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 8010 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8011 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 8012 | // do no retry forever checking for TLS version interference. This is a |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 8013 | // regression test for https://crbug.com/823387. The version interference probe |
| 8014 | // has since been removed, but retain the regression test so we can update it if |
| 8015 | // we add future TLS retries. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8016 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 8017 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 8018 | // https://origin/. |
| 8019 | session_deps_.proxy_resolution_service = |
| 8020 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8021 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8022 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 8023 | SSLContextConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8024 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 8025 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8026 | |
| 8027 | HttpRequestInfo request; |
| 8028 | request.method = "GET"; |
| 8029 | request.url = GURL("https://origin/"); |
| 8030 | request.traffic_annotation = |
| 8031 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 8032 | |
| 8033 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 8034 | // to other auth schemes. |
| 8035 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 8036 | |
| 8037 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 8038 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 8039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8040 | |
| 8041 | // Generate the NTLM messages based on known test data. |
| 8042 | std::string negotiate_msg; |
| 8043 | std::string challenge_msg; |
| 8044 | std::string authenticate_msg; |
| 8045 | base::Base64Encode( |
| 8046 | base::StringPiece( |
| 8047 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8048 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8049 | &negotiate_msg); |
| 8050 | base::Base64Encode( |
| 8051 | base::StringPiece( |
| 8052 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8053 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8054 | &challenge_msg); |
| 8055 | base::Base64Encode( |
| 8056 | base::StringPiece( |
| 8057 | reinterpret_cast<const char*>( |
| 8058 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 8059 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8060 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 8061 | &authenticate_msg); |
| 8062 | |
| 8063 | MockWrite data_writes[] = { |
| 8064 | // The initial CONNECT request. |
| 8065 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8066 | "Host: origin:443\r\n" |
| 8067 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8068 | |
| 8069 | // After restarting with an identity. |
| 8070 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8071 | "Host: origin:443\r\n" |
| 8072 | "Proxy-Connection: keep-alive\r\n" |
| 8073 | "Proxy-Authorization: NTLM "), |
| 8074 | MockWrite(negotiate_msg.c_str()), |
| 8075 | // End headers. |
| 8076 | MockWrite("\r\n\r\n"), |
| 8077 | |
| 8078 | // The second restart. |
| 8079 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 8080 | "Host: origin:443\r\n" |
| 8081 | "Proxy-Connection: keep-alive\r\n" |
| 8082 | "Proxy-Authorization: NTLM "), |
| 8083 | MockWrite(authenticate_msg.c_str()), |
| 8084 | // End headers. |
| 8085 | MockWrite("\r\n\r\n"), |
| 8086 | }; |
| 8087 | |
| 8088 | MockRead data_reads[] = { |
| 8089 | // The initial NTLM response. |
| 8090 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 8091 | "Content-Length: 0\r\n" |
| 8092 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 8093 | |
| 8094 | // The NTLM challenge message. |
| 8095 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 8096 | "Content-Length: 0\r\n" |
| 8097 | "Proxy-Authenticate: NTLM "), |
| 8098 | MockRead(challenge_msg.c_str()), |
| 8099 | // End headers. |
| 8100 | MockRead("\r\n\r\n"), |
| 8101 | |
| 8102 | // Finally the tunnel is established. |
| 8103 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 8104 | }; |
| 8105 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8106 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8107 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8110 | |
| 8111 | // Start the transaction. The proxy responds with an NTLM authentication |
| 8112 | // request. |
| 8113 | TestCompletionCallback callback; |
| 8114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8115 | int rv = callback.GetResult( |
| 8116 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 8117 | |
| 8118 | EXPECT_THAT(rv, IsOk()); |
| 8119 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 8120 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8121 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8122 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8123 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 8124 | // Configure credentials and restart. The proxy responds with the challenge |
| 8125 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8126 | rv = callback.GetResult(trans.RestartWithAuth( |
| 8127 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 8128 | callback.callback())); |
| 8129 | EXPECT_THAT(rv, IsOk()); |
| 8130 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 8131 | response = trans.GetResponseInfo(); |
| 8132 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8133 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8134 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 8135 | // Restart once more. The tunnel will be established and then the SSL |
| 8136 | // handshake will reset. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 8137 | rv = callback.GetResult( |
| 8138 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 8139 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 8140 | } |
| 8141 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8142 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 8143 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8144 | // Test reading a server response which has only headers, and no body. |
| 8145 | // After some maximum number of bytes is consumed, the transaction should |
| 8146 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8147 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8148 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8150 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8151 | request.traffic_annotation = |
| 8152 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8153 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8156 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8157 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 8158 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 8159 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8160 | |
| 8161 | MockRead data_reads[] = { |
| 8162 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8163 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8164 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8165 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8166 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8167 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8168 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8170 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8171 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8172 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8174 | |
| 8175 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8176 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 8177 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8178 | |
| 8179 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 8180 | // establish tunnel. |
| 8181 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8182 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8183 | HttpRequestInfo request; |
| 8184 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8185 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8186 | request.traffic_annotation = |
| 8187 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8188 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8189 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8190 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8191 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 8192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8194 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8195 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8196 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8197 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8198 | // Since we have proxy, should try to establish tunnel. |
| 8199 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8200 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8201 | "Host: www.example.org:443\r\n" |
| 8202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8203 | }; |
| 8204 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 8205 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8206 | // connection. Usually a proxy would return 501 (not implemented), |
| 8207 | // or 200 (tunnel established). |
| 8208 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 8209 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8210 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8211 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8212 | }; |
| 8213 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8214 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8215 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8217 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8218 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8219 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8221 | |
| 8222 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8223 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8224 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8225 | // Empty the current queue. This is necessary because idle sockets are |
| 8226 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8227 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8228 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8229 | // We now check to make sure the TCPClientSocket was not added back to |
| 8230 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8231 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8232 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8233 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8234 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8235 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 8236 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8237 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8238 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8239 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8240 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8241 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8242 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8243 | request.traffic_annotation = |
| 8244 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8245 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8249 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8250 | MockRead data_reads[] = { |
| 8251 | // A part of the response body is received with the response headers. |
| 8252 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8253 | // The rest of the response body is received in two parts. |
| 8254 | MockRead("lo"), |
| 8255 | MockRead(" world"), |
| 8256 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8257 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8258 | }; |
| 8259 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8260 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8261 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8263 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8264 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8265 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8267 | |
| 8268 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8271 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8272 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8273 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8274 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8275 | std::string status_line = response->headers->GetStatusLine(); |
| 8276 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8277 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8278 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8279 | |
| 8280 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8281 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8283 | EXPECT_EQ("hello world", response_data); |
| 8284 | |
| 8285 | // Empty the current queue. This is necessary because idle sockets are |
| 8286 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8287 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8288 | |
| 8289 | // 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] | 8290 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 8291 | } |
| 8292 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8293 | // Make sure that we recycle a SSL socket after reading all of the response |
| 8294 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8295 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8296 | HttpRequestInfo request; |
| 8297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8298 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8299 | request.traffic_annotation = |
| 8300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8301 | |
| 8302 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8303 | MockWrite( |
| 8304 | "GET / HTTP/1.1\r\n" |
| 8305 | "Host: www.example.org\r\n" |
| 8306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8307 | }; |
| 8308 | |
| 8309 | MockRead data_reads[] = { |
| 8310 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8311 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8312 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8313 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8314 | }; |
| 8315 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8316 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8318 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8319 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8322 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8326 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8328 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8330 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8331 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8332 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8333 | ASSERT_TRUE(response); |
| 8334 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8335 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8336 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8337 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8338 | |
| 8339 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8340 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8342 | EXPECT_EQ("hello world", response_data); |
| 8343 | |
| 8344 | // Empty the current queue. This is necessary because idle sockets are |
| 8345 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8346 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8347 | |
| 8348 | // 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] | 8349 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8353 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8354 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8355 | HttpRequestInfo request; |
| 8356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8357 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8358 | request.traffic_annotation = |
| 8359 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8360 | |
| 8361 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8362 | MockWrite( |
| 8363 | "GET / HTTP/1.1\r\n" |
| 8364 | "Host: www.example.org\r\n" |
| 8365 | "Connection: keep-alive\r\n\r\n"), |
| 8366 | MockWrite( |
| 8367 | "GET / HTTP/1.1\r\n" |
| 8368 | "Host: www.example.org\r\n" |
| 8369 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8370 | }; |
| 8371 | |
| 8372 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8373 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8374 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8375 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8376 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8377 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8380 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8381 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8382 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8383 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8384 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8386 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8389 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8390 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8391 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8392 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8393 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8395 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8396 | |
| 8397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8398 | ASSERT_TRUE(response); |
| 8399 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8400 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8401 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8402 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8403 | |
| 8404 | std::string response_data; |
| 8405 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8407 | EXPECT_EQ("hello world", response_data); |
| 8408 | |
| 8409 | // Empty the current queue. This is necessary because idle sockets are |
| 8410 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8411 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8412 | |
| 8413 | // 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] | 8414 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8415 | |
| 8416 | // Now start the second transaction, which should reuse the previous socket. |
| 8417 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8418 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8419 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8420 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8421 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8422 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8424 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8425 | |
| 8426 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8427 | ASSERT_TRUE(response); |
| 8428 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8429 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8430 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8431 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8432 | |
| 8433 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8434 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8435 | EXPECT_EQ("hello world", response_data); |
| 8436 | |
| 8437 | // Empty the current queue. This is necessary because idle sockets are |
| 8438 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8439 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8440 | |
| 8441 | // 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] | 8442 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8443 | } |
| 8444 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8445 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8446 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8447 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8448 | HttpRequestInfo request; |
| 8449 | request.method = "GET"; |
| 8450 | request.url = GURL("http://www.example.org/"); |
| 8451 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8452 | request.traffic_annotation = |
| 8453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8454 | |
| 8455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8458 | |
| 8459 | MockRead data_reads[] = { |
| 8460 | // A part of the response body is received with the response headers. |
| 8461 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8462 | // The rest of the response body is received in two parts. |
| 8463 | MockRead("lo"), MockRead(" world"), |
| 8464 | MockRead("junk"), // Should not be read!! |
| 8465 | MockRead(SYNCHRONOUS, OK), |
| 8466 | }; |
| 8467 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8468 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8469 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8470 | |
| 8471 | TestCompletionCallback callback; |
| 8472 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8473 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8475 | |
| 8476 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8479 | ASSERT_TRUE(response); |
| 8480 | EXPECT_TRUE(response->headers); |
| 8481 | std::string status_line = response->headers->GetStatusLine(); |
| 8482 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8483 | |
| 8484 | // Make memory critical notification and ensure the transaction still has been |
| 8485 | // operating right. |
| 8486 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8487 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8488 | base::RunLoop().RunUntilIdle(); |
| 8489 | |
| 8490 | // Socket should not be flushed as long as it is not idle. |
| 8491 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 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. |
| 8503 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8504 | |
| 8505 | // Idle sockets should be flushed now. |
| 8506 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8507 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8508 | base::RunLoop().RunUntilIdle(); |
| 8509 | |
| 8510 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8511 | } |
| 8512 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8513 | // Disable idle socket closing on memory pressure. |
| 8514 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8515 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8516 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8517 | HttpRequestInfo request; |
| 8518 | request.method = "GET"; |
| 8519 | request.url = GURL("http://www.example.org/"); |
| 8520 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8521 | request.traffic_annotation = |
| 8522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8523 | |
| 8524 | // Disable idle socket closing on memory pressure. |
| 8525 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8527 | |
| 8528 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8529 | |
| 8530 | MockRead data_reads[] = { |
| 8531 | // A part of the response body is received with the response headers. |
| 8532 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8533 | // The rest of the response body is received in two parts. |
| 8534 | MockRead("lo"), MockRead(" world"), |
| 8535 | MockRead("junk"), // Should not be read!! |
| 8536 | MockRead(SYNCHRONOUS, OK), |
| 8537 | }; |
| 8538 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8539 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8540 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8541 | |
| 8542 | TestCompletionCallback callback; |
| 8543 | |
| 8544 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8546 | |
| 8547 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8548 | |
| 8549 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8550 | ASSERT_TRUE(response); |
| 8551 | EXPECT_TRUE(response->headers); |
| 8552 | std::string status_line = response->headers->GetStatusLine(); |
| 8553 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8554 | |
| 8555 | // Make memory critical notification and ensure the transaction still has been |
| 8556 | // operating right. |
| 8557 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8558 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8559 | base::RunLoop().RunUntilIdle(); |
| 8560 | |
| 8561 | // Socket should not be flushed as long as it is not idle. |
| 8562 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8563 | |
| 8564 | std::string response_data; |
| 8565 | rv = ReadTransaction(&trans, &response_data); |
| 8566 | EXPECT_THAT(rv, IsOk()); |
| 8567 | EXPECT_EQ("hello world", response_data); |
| 8568 | |
| 8569 | // Empty the current queue. This is necessary because idle sockets are |
| 8570 | // added to the connection pool asynchronously with a PostTask. |
| 8571 | base::RunLoop().RunUntilIdle(); |
| 8572 | |
| 8573 | // We now check to make sure the socket was added back to the pool. |
| 8574 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8575 | |
| 8576 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8577 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8578 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8579 | base::RunLoop().RunUntilIdle(); |
| 8580 | |
| 8581 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8582 | |
| 8583 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8584 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8585 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8586 | base::RunLoop().RunUntilIdle(); |
| 8587 | |
| 8588 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8589 | } |
| 8590 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8591 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8592 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8593 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8594 | HttpRequestInfo request; |
| 8595 | request.method = "GET"; |
| 8596 | request.url = GURL("https://www.example.org/"); |
| 8597 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8598 | request.traffic_annotation = |
| 8599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8600 | |
| 8601 | MockWrite data_writes[] = { |
| 8602 | MockWrite("GET / HTTP/1.1\r\n" |
| 8603 | "Host: www.example.org\r\n" |
| 8604 | "Connection: keep-alive\r\n\r\n"), |
| 8605 | }; |
| 8606 | |
| 8607 | MockRead data_reads[] = { |
| 8608 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8609 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8610 | |
| 8611 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8613 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8614 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8616 | |
| 8617 | TestCompletionCallback callback; |
| 8618 | |
| 8619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8621 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8622 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8624 | |
| 8625 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8626 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8627 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8628 | ASSERT_TRUE(response); |
| 8629 | ASSERT_TRUE(response->headers); |
| 8630 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8631 | |
| 8632 | // Make memory critical notification and ensure the transaction still has been |
| 8633 | // operating right. |
| 8634 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8635 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8636 | base::RunLoop().RunUntilIdle(); |
| 8637 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8638 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8639 | |
| 8640 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8641 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8642 | EXPECT_THAT(rv, IsOk()); |
| 8643 | EXPECT_EQ("hello world", response_data); |
| 8644 | |
| 8645 | // Empty the current queue. This is necessary because idle sockets are |
| 8646 | // added to the connection pool asynchronously with a PostTask. |
| 8647 | base::RunLoop().RunUntilIdle(); |
| 8648 | |
| 8649 | // 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] | 8650 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8651 | |
| 8652 | // Make memory notification once again and ensure idle socket is closed. |
| 8653 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8654 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8655 | base::RunLoop().RunUntilIdle(); |
| 8656 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8657 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8658 | } |
| 8659 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8660 | // Make sure that we recycle a socket after a zero-length response. |
| 8661 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8662 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8663 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8664 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8665 | request.url = GURL( |
| 8666 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8667 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8668 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8669 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8670 | request.traffic_annotation = |
| 8671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8672 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8674 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8675 | MockRead data_reads[] = { |
| 8676 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8677 | "Content-Length: 0\r\n" |
| 8678 | "Content-Type: text/html\r\n\r\n"), |
| 8679 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8680 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8681 | }; |
| 8682 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8683 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8684 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8685 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8686 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8687 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8690 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8691 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8692 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8694 | |
| 8695 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8696 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8698 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8699 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8700 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8701 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8702 | std::string status_line = response->headers->GetStatusLine(); |
| 8703 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8704 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8705 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8706 | |
| 8707 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8708 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8709 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8710 | EXPECT_EQ("", response_data); |
| 8711 | |
| 8712 | // Empty the current queue. This is necessary because idle sockets are |
| 8713 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8714 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8715 | |
| 8716 | // 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] | 8717 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8718 | } |
| 8719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8720 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8721 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8722 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8723 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8724 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8725 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8726 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8727 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8728 | // after use. |
| 8729 | request[0].method = "GET"; |
| 8730 | request[0].url = GURL("http://www.google.com/"); |
| 8731 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8732 | request[0].traffic_annotation = |
| 8733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8734 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8735 | // transaction 1. The first attempts fails when writing the POST data. |
| 8736 | // This causes the transaction to retry with a new socket. The second |
| 8737 | // attempt succeeds. |
| 8738 | request[1].method = "POST"; |
| 8739 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8740 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8741 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8742 | request[1].traffic_annotation = |
| 8743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8744 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8746 | |
| 8747 | // The first socket is used for transaction 1 and the first attempt of |
| 8748 | // transaction 2. |
| 8749 | |
| 8750 | // The response of transaction 1. |
| 8751 | MockRead data_reads1[] = { |
| 8752 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8753 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8755 | }; |
| 8756 | // The mock write results of transaction 1 and the first attempt of |
| 8757 | // transaction 2. |
| 8758 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8759 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8760 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8761 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8762 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8763 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8764 | |
| 8765 | // The second socket is used for the second attempt of transaction 2. |
| 8766 | |
| 8767 | // The response of transaction 2. |
| 8768 | MockRead data_reads2[] = { |
| 8769 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8770 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8771 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8772 | }; |
| 8773 | // The mock write results of the second attempt of transaction 2. |
| 8774 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8775 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8776 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8777 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8778 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8779 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8780 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8781 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8782 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8783 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8784 | "hello world", "welcome" |
| 8785 | }; |
| 8786 | |
| 8787 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8788 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8790 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8791 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8792 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8794 | |
| 8795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8798 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8799 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8800 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8801 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8802 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8803 | |
| 8804 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8805 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8807 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8808 | } |
| 8809 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8810 | |
| 8811 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8812 | // 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] | 8813 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8814 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8815 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8817 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8818 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8819 | request.traffic_annotation = |
| 8820 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8821 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8824 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8825 | // The password contains an escaped character -- for this test to pass it |
| 8826 | // will need to be unescaped by HttpNetworkTransaction. |
| 8827 | EXPECT_EQ("b%40r", request.url.password()); |
| 8828 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8829 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8830 | MockWrite( |
| 8831 | "GET / HTTP/1.1\r\n" |
| 8832 | "Host: www.example.org\r\n" |
| 8833 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8834 | }; |
| 8835 | |
| 8836 | MockRead data_reads1[] = { |
| 8837 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8838 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8839 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8840 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8841 | }; |
| 8842 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8843 | // After the challenge above, the transaction will be restarted using the |
| 8844 | // identity from the url (foo, b@r) to answer the challenge. |
| 8845 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8846 | MockWrite( |
| 8847 | "GET / HTTP/1.1\r\n" |
| 8848 | "Host: www.example.org\r\n" |
| 8849 | "Connection: keep-alive\r\n" |
| 8850 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8851 | }; |
| 8852 | |
| 8853 | MockRead data_reads2[] = { |
| 8854 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8855 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8856 | MockRead(SYNCHRONOUS, OK), |
| 8857 | }; |
| 8858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8859 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8860 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8861 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8862 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8863 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8864 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8865 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8867 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8868 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8869 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8870 | |
| 8871 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8872 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8874 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8875 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8876 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8877 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8878 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8879 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8880 | |
| 8881 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8882 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8883 | |
| 8884 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8885 | |
| 8886 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8887 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8888 | } |
| 8889 | |
| 8890 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8891 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8892 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8893 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8894 | HttpRequestInfo request; |
| 8895 | request.method = "GET"; |
| 8896 | // Note: the URL has a username:password in it. The password "baz" is |
| 8897 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8898 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8899 | |
| 8900 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8901 | request.traffic_annotation = |
| 8902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8903 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8904 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8905 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8906 | |
| 8907 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8908 | MockWrite( |
| 8909 | "GET / HTTP/1.1\r\n" |
| 8910 | "Host: www.example.org\r\n" |
| 8911 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8912 | }; |
| 8913 | |
| 8914 | MockRead data_reads1[] = { |
| 8915 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8916 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8917 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8918 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8919 | }; |
| 8920 | |
| 8921 | // After the challenge above, the transaction will be restarted using the |
| 8922 | // identity from the url (foo, baz) to answer the challenge. |
| 8923 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | MockWrite( |
| 8925 | "GET / HTTP/1.1\r\n" |
| 8926 | "Host: www.example.org\r\n" |
| 8927 | "Connection: keep-alive\r\n" |
| 8928 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8929 | }; |
| 8930 | |
| 8931 | MockRead data_reads2[] = { |
| 8932 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8933 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8934 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8935 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8936 | }; |
| 8937 | |
| 8938 | // After the challenge above, the transaction will be restarted using the |
| 8939 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8940 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8941 | MockWrite( |
| 8942 | "GET / HTTP/1.1\r\n" |
| 8943 | "Host: www.example.org\r\n" |
| 8944 | "Connection: keep-alive\r\n" |
| 8945 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8946 | }; |
| 8947 | |
| 8948 | MockRead data_reads3[] = { |
| 8949 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8950 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8951 | MockRead(SYNCHRONOUS, OK), |
| 8952 | }; |
| 8953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8954 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8955 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8956 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8958 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8959 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8960 | |
| 8961 | TestCompletionCallback callback1; |
| 8962 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 8963 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8965 | |
| 8966 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8967 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8969 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8970 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8971 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8973 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8974 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8975 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8977 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8978 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8979 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8980 | |
| 8981 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8982 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8984 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8985 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8986 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8988 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8989 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8990 | |
| 8991 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8992 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8993 | |
| 8994 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8995 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8996 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8997 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8998 | } |
| 8999 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9000 | |
| 9001 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 9002 | // correct identity in the URL, but its use is being suppressed. The identity |
| 9003 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9004 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9005 | HttpRequestInfo request; |
| 9006 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9007 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9008 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9009 | request.traffic_annotation = |
| 9010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9011 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9013 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9014 | |
| 9015 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9016 | MockWrite( |
| 9017 | "GET / HTTP/1.1\r\n" |
| 9018 | "Host: www.example.org\r\n" |
| 9019 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9020 | }; |
| 9021 | |
| 9022 | MockRead data_reads1[] = { |
| 9023 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9024 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9025 | MockRead("Content-Length: 10\r\n\r\n"), |
| 9026 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 9027 | }; |
| 9028 | |
| 9029 | // After the challenge above, the transaction will be restarted using the |
| 9030 | // identity supplied by the user, not the one in the URL, to answer the |
| 9031 | // challenge. |
| 9032 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9033 | MockWrite( |
| 9034 | "GET / HTTP/1.1\r\n" |
| 9035 | "Host: www.example.org\r\n" |
| 9036 | "Connection: keep-alive\r\n" |
| 9037 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9038 | }; |
| 9039 | |
| 9040 | MockRead data_reads3[] = { |
| 9041 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9042 | MockRead("Content-Length: 100\r\n\r\n"), |
| 9043 | MockRead(SYNCHRONOUS, OK), |
| 9044 | }; |
| 9045 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9046 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9047 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9048 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9049 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9050 | |
| 9051 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9052 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9054 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9055 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9056 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9058 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9059 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9060 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9061 | |
| 9062 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9063 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9065 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9066 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9067 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9068 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9069 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9070 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9071 | |
| 9072 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9073 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9074 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9075 | |
| 9076 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9077 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 9078 | } |
| 9079 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9080 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9081 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9083 | |
| 9084 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9085 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9086 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9088 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9089 | request.traffic_annotation = |
| 9090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9092 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9093 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9094 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9095 | MockWrite( |
| 9096 | "GET /x/y/z HTTP/1.1\r\n" |
| 9097 | "Host: www.example.org\r\n" |
| 9098 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9099 | }; |
| 9100 | |
| 9101 | MockRead data_reads1[] = { |
| 9102 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9103 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9104 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9105 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9106 | }; |
| 9107 | |
| 9108 | // Resend with authorization (username=foo, password=bar) |
| 9109 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9110 | MockWrite( |
| 9111 | "GET /x/y/z HTTP/1.1\r\n" |
| 9112 | "Host: www.example.org\r\n" |
| 9113 | "Connection: keep-alive\r\n" |
| 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 authorization. |
| 9118 | MockRead data_reads2[] = { |
| 9119 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9120 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9121 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9122 | }; |
| 9123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9124 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9125 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9126 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9127 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9129 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9130 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9131 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9133 | |
| 9134 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9137 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9138 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9139 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9141 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9143 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9144 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9145 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9146 | |
| 9147 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9148 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9150 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9151 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9152 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9153 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9154 | } |
| 9155 | |
| 9156 | // ------------------------------------------------------------------------ |
| 9157 | |
| 9158 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 9159 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9160 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9161 | request.method = "GET"; |
| 9162 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9163 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9164 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9165 | request.traffic_annotation = |
| 9166 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9168 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9169 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9170 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9171 | MockWrite( |
| 9172 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9173 | "Host: www.example.org\r\n" |
| 9174 | "Connection: keep-alive\r\n" |
| 9175 | // Send preemptive authorization for MyRealm1 |
| 9176 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9177 | }; |
| 9178 | |
| 9179 | // The server didn't like the preemptive authorization, and |
| 9180 | // challenges us for a different realm (MyRealm2). |
| 9181 | MockRead data_reads1[] = { |
| 9182 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9183 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 9184 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9185 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9186 | }; |
| 9187 | |
| 9188 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 9189 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9190 | MockWrite( |
| 9191 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9192 | "Host: www.example.org\r\n" |
| 9193 | "Connection: keep-alive\r\n" |
| 9194 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9195 | }; |
| 9196 | |
| 9197 | // Sever accepts the authorization. |
| 9198 | MockRead data_reads2[] = { |
| 9199 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9200 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9201 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9202 | }; |
| 9203 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9204 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9205 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9206 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9207 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9209 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9210 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9211 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9213 | |
| 9214 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9215 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9216 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9217 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9218 | ASSERT_TRUE(response); |
| 9219 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9220 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9221 | EXPECT_EQ("http://www.example.org", |
| 9222 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9223 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 9224 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9226 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9228 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 9229 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9231 | |
| 9232 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9235 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9236 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9237 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9238 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9239 | } |
| 9240 | |
| 9241 | // ------------------------------------------------------------------------ |
| 9242 | |
| 9243 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 9244 | // succeed with preemptive authorization. |
| 9245 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9246 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9247 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9248 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9249 | request.traffic_annotation = |
| 9250 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9252 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9253 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9254 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9255 | MockWrite( |
| 9256 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 9257 | "Host: www.example.org\r\n" |
| 9258 | "Connection: keep-alive\r\n" |
| 9259 | // The authorization for MyRealm1 gets sent preemptively |
| 9260 | // (since the url is in the same protection space) |
| 9261 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9262 | }; |
| 9263 | |
| 9264 | // Sever accepts the preemptive authorization |
| 9265 | MockRead data_reads1[] = { |
| 9266 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9267 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9268 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9269 | }; |
| 9270 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9271 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9272 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9274 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9275 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9276 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9278 | |
| 9279 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9282 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9283 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9284 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9285 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9286 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9287 | } |
| 9288 | |
| 9289 | // ------------------------------------------------------------------------ |
| 9290 | |
| 9291 | // Transaction 4: request another URL in MyRealm (however the |
| 9292 | // url is not known to belong to the protection space, so no pre-auth). |
| 9293 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9294 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9295 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9296 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9297 | request.traffic_annotation = |
| 9298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9301 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9302 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9303 | MockWrite( |
| 9304 | "GET /x/1 HTTP/1.1\r\n" |
| 9305 | "Host: www.example.org\r\n" |
| 9306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9307 | }; |
| 9308 | |
| 9309 | MockRead data_reads1[] = { |
| 9310 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9311 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9312 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9313 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9314 | }; |
| 9315 | |
| 9316 | // Resend with authorization from MyRealm's cache. |
| 9317 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9318 | MockWrite( |
| 9319 | "GET /x/1 HTTP/1.1\r\n" |
| 9320 | "Host: www.example.org\r\n" |
| 9321 | "Connection: keep-alive\r\n" |
| 9322 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9323 | }; |
| 9324 | |
| 9325 | // Sever accepts the authorization. |
| 9326 | MockRead data_reads2[] = { |
| 9327 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9328 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9329 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9330 | }; |
| 9331 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9332 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9333 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9334 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9335 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9337 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9338 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9339 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9341 | |
| 9342 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9343 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9345 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9346 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9347 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9349 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9350 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9351 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9353 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9354 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9355 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9356 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9357 | } |
| 9358 | |
| 9359 | // ------------------------------------------------------------------------ |
| 9360 | |
| 9361 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9362 | // cached identity. Should invalidate and re-prompt. |
| 9363 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9364 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9365 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9366 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9367 | request.traffic_annotation = |
| 9368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9371 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9372 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9373 | MockWrite( |
| 9374 | "GET /p/q/t HTTP/1.1\r\n" |
| 9375 | "Host: www.example.org\r\n" |
| 9376 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9377 | }; |
| 9378 | |
| 9379 | MockRead data_reads1[] = { |
| 9380 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9381 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9382 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9383 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9384 | }; |
| 9385 | |
| 9386 | // Resend with authorization from cache for MyRealm. |
| 9387 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9388 | MockWrite( |
| 9389 | "GET /p/q/t HTTP/1.1\r\n" |
| 9390 | "Host: www.example.org\r\n" |
| 9391 | "Connection: keep-alive\r\n" |
| 9392 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9393 | }; |
| 9394 | |
| 9395 | // Sever rejects the authorization. |
| 9396 | MockRead data_reads2[] = { |
| 9397 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9398 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9399 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9400 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9401 | }; |
| 9402 | |
| 9403 | // At this point we should prompt for new credentials for MyRealm. |
| 9404 | // Restart with username=foo3, password=foo4. |
| 9405 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9406 | MockWrite( |
| 9407 | "GET /p/q/t HTTP/1.1\r\n" |
| 9408 | "Host: www.example.org\r\n" |
| 9409 | "Connection: keep-alive\r\n" |
| 9410 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9411 | }; |
| 9412 | |
| 9413 | // Sever accepts the authorization. |
| 9414 | MockRead data_reads3[] = { |
| 9415 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9416 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9417 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9418 | }; |
| 9419 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9420 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9421 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9422 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9423 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9424 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9425 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9427 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9428 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9429 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9431 | |
| 9432 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9435 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9436 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9437 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9439 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9441 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9443 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9444 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9445 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9447 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9449 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9450 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9452 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9453 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9454 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9456 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9457 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9458 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9459 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9460 | } |
| 9461 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9462 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9463 | // Tests that nonce count increments when multiple auth attempts |
| 9464 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9465 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9466 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9467 | new HttpAuthHandlerDigest::Factory(); |
| 9468 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9469 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9470 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9471 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9473 | |
| 9474 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9475 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9476 | HttpRequestInfo request; |
| 9477 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9478 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9479 | request.traffic_annotation = |
| 9480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9483 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9484 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9485 | MockWrite( |
| 9486 | "GET /x/y/z HTTP/1.1\r\n" |
| 9487 | "Host: www.example.org\r\n" |
| 9488 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9489 | }; |
| 9490 | |
| 9491 | MockRead data_reads1[] = { |
| 9492 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9493 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9494 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9495 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9496 | }; |
| 9497 | |
| 9498 | // Resend with authorization (username=foo, password=bar) |
| 9499 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9500 | MockWrite( |
| 9501 | "GET /x/y/z HTTP/1.1\r\n" |
| 9502 | "Host: www.example.org\r\n" |
| 9503 | "Connection: keep-alive\r\n" |
| 9504 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9505 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9506 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9507 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9508 | }; |
| 9509 | |
| 9510 | // Sever accepts the authorization. |
| 9511 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9512 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9513 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9514 | }; |
| 9515 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9516 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9517 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9518 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9519 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9521 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9522 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9523 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9524 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9525 | |
| 9526 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9527 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9529 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9530 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9531 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9533 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9535 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9536 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9538 | |
| 9539 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9542 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9543 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9544 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9545 | } |
| 9546 | |
| 9547 | // ------------------------------------------------------------------------ |
| 9548 | |
| 9549 | // Transaction 2: Request another resource in digestive's protection space. |
| 9550 | // This will preemptively add an Authorization header which should have an |
| 9551 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9552 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9553 | HttpRequestInfo request; |
| 9554 | request.method = "GET"; |
| 9555 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9556 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9557 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9558 | request.traffic_annotation = |
| 9559 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9562 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9563 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9564 | MockWrite( |
| 9565 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9566 | "Host: www.example.org\r\n" |
| 9567 | "Connection: keep-alive\r\n" |
| 9568 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9569 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9570 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9571 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9572 | }; |
| 9573 | |
| 9574 | // Sever accepts the authorization. |
| 9575 | MockRead data_reads1[] = { |
| 9576 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9577 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9578 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9579 | }; |
| 9580 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9581 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9582 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9584 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9585 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9586 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9588 | |
| 9589 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9590 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9593 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9594 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9595 | } |
| 9596 | } |
| 9597 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9598 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9599 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9600 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9603 | |
| 9604 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9605 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9606 | trans.read_buf_len_ = 15; |
| 9607 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9608 | |
| 9609 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9610 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9611 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9612 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9613 | response->response_time = base::Time::Now(); |
| 9614 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9615 | |
| 9616 | { // Setup state for response_.vary_data |
| 9617 | HttpRequestInfo request; |
| 9618 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9619 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9620 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9621 | request.extra_headers.SetHeader("Foo", "1"); |
| 9622 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9623 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9624 | } |
| 9625 | |
| 9626 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9627 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9628 | |
| 9629 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9630 | EXPECT_FALSE(trans.read_buf_); |
| 9631 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9632 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9633 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9634 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9635 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9636 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9637 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9638 | } |
| 9639 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9640 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9641 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9642 | HttpRequestInfo request; |
| 9643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9644 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9645 | request.traffic_annotation = |
| 9646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9650 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9651 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9652 | MockWrite( |
| 9653 | "GET / HTTP/1.1\r\n" |
| 9654 | "Host: www.example.org\r\n" |
| 9655 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9656 | }; |
| 9657 | |
| 9658 | MockRead data_reads[] = { |
| 9659 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9660 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9661 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9662 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9663 | }; |
| 9664 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9665 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9666 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9667 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9668 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9669 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9670 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9672 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9673 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9675 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9676 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9677 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9679 | |
| 9680 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9681 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9683 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9685 | |
| 9686 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9687 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9689 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9690 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9691 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9692 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9693 | } |
| 9694 | |
| 9695 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9696 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9697 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9698 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9699 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9700 | |
| 9701 | HttpRequestInfo request; |
| 9702 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9703 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9704 | request.traffic_annotation = |
| 9705 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9706 | |
| 9707 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9708 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9709 | "Host: www.example.org:443\r\n" |
| 9710 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9711 | }; |
| 9712 | |
| 9713 | MockRead proxy_reads[] = { |
| 9714 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9715 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9716 | }; |
| 9717 | |
| 9718 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9719 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9720 | "Host: www.example.org:443\r\n" |
| 9721 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9722 | MockWrite("GET / HTTP/1.1\r\n" |
| 9723 | "Host: www.example.org\r\n" |
| 9724 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9725 | }; |
| 9726 | |
| 9727 | MockRead data_reads[] = { |
| 9728 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9729 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9730 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9731 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9733 | }; |
| 9734 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9735 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9736 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9737 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9738 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9739 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9740 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9744 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9745 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9746 | |
| 9747 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9748 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9749 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9750 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9751 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9752 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9753 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9754 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9755 | |
| 9756 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9757 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9759 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9761 | |
| 9762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9765 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9766 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9767 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9768 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9769 | } |
| 9770 | } |
| 9771 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9772 | |
| 9773 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9774 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9775 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9776 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9777 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9778 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9779 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9780 | |
| 9781 | HttpRequestInfo request; |
| 9782 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9783 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9784 | request.traffic_annotation = |
| 9785 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9786 | |
| 9787 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9788 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9789 | "Host: www.example.org:443\r\n" |
| 9790 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9791 | MockWrite("GET / HTTP/1.1\r\n" |
| 9792 | "Host: www.example.org\r\n" |
| 9793 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9794 | }; |
| 9795 | |
| 9796 | MockRead data_reads[] = { |
| 9797 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9798 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9799 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9802 | }; |
| 9803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9804 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9805 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9806 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9812 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9816 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9819 | |
| 9820 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9821 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9822 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9823 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9824 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9825 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9826 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9827 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9828 | EXPECT_EQ(200, response->headers->response_code()); |
| 9829 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9830 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9831 | |
| 9832 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9833 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9834 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9835 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9836 | } |
| 9837 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9838 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9839 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9840 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9841 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9842 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9843 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9844 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9845 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9846 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9847 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9848 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9849 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9850 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9852 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9853 | request.traffic_annotation = |
| 9854 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9855 | |
| 9856 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9857 | MockWrite(ASYNC, 0, |
| 9858 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9859 | "Host: www.example.org:443\r\n" |
| 9860 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9861 | }; |
| 9862 | |
| 9863 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9864 | // Pause on first read. |
| 9865 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9866 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9867 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9868 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9869 | }; |
| 9870 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9871 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9872 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9873 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9874 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9877 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9881 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 9882 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9884 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9885 | |
| 9886 | // Host resolution takes |kTimeIncrement|. |
| 9887 | FastForwardBy(kTimeIncrement); |
| 9888 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9889 | // request to instantly complete, and the async connect will start as well. |
| 9890 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9891 | |
| 9892 | // Connecting takes |kTimeIncrement|. |
| 9893 | FastForwardBy(kTimeIncrement); |
| 9894 | data.RunUntilPaused(); |
| 9895 | |
| 9896 | // The server takes |kTimeIncrement| to respond. |
| 9897 | FastForwardBy(kTimeIncrement); |
| 9898 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9899 | |
| 9900 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9901 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9902 | } |
| 9903 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9904 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9905 | TEST_F(HttpNetworkTransactionTest, |
| 9906 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9907 | base::HistogramTester histograms; |
| 9908 | session_deps_.proxy_resolution_service = |
| 9909 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9910 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9911 | TestNetLog net_log; |
| 9912 | session_deps_.net_log = &net_log; |
| 9913 | |
| 9914 | HttpRequestInfo request; |
| 9915 | request.method = "GET"; |
| 9916 | request.url = GURL("https://www.example.org/"); |
| 9917 | request.traffic_annotation = |
| 9918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9919 | |
| 9920 | MockWrite data_writes[] = { |
| 9921 | MockWrite(ASYNC, 0, |
| 9922 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9923 | "Host: www.example.org:443\r\n" |
| 9924 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9925 | }; |
| 9926 | |
| 9927 | MockRead data_reads[] = { |
| 9928 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9929 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9930 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9931 | }; |
| 9932 | |
| 9933 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9934 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9935 | |
| 9936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9938 | |
| 9939 | TestCompletionCallback callback; |
| 9940 | |
| 9941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9942 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9943 | |
| 9944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9946 | |
| 9947 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9948 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9949 | } |
| 9950 | |
| 9951 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9952 | // request for main frames. |
| 9953 | TEST_F(HttpNetworkTransactionTest, |
| 9954 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9955 | base::HistogramTester histograms; |
| 9956 | session_deps_.proxy_resolution_service = |
| 9957 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9958 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9959 | TestNetLog net_log; |
| 9960 | session_deps_.net_log = &net_log; |
| 9961 | |
| 9962 | HttpRequestInfo request; |
| 9963 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9964 | request.method = "GET"; |
| 9965 | request.url = GURL("https://www.example.org/"); |
| 9966 | request.traffic_annotation = |
| 9967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9968 | |
| 9969 | MockWrite data_writes[] = { |
| 9970 | MockWrite(ASYNC, 0, |
| 9971 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9972 | "Host: www.example.org:443\r\n" |
| 9973 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9974 | }; |
| 9975 | |
| 9976 | MockRead data_reads[] = { |
| 9977 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9978 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9979 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9980 | }; |
| 9981 | |
| 9982 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9983 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9984 | |
| 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9987 | |
| 9988 | TestCompletionCallback callback; |
| 9989 | |
| 9990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9992 | |
| 9993 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9995 | |
| 9996 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9997 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9998 | } |
| 9999 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 10000 | // 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] | 10001 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10002 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10003 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10004 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10005 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10006 | TestNetLog net_log; |
| 10007 | session_deps_.net_log = &net_log; |
| 10008 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10009 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 10010 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10011 | |
| 10012 | HttpRequestInfo request; |
| 10013 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 10014 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10015 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10016 | request.traffic_annotation = |
| 10017 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10018 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10019 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10020 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10021 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10022 | spdy::SpdySerializedFrame goaway( |
| 10023 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10024 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10025 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10026 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10027 | }; |
| 10028 | |
| 10029 | static const char* const kExtraHeaders[] = { |
| 10030 | "location", |
| 10031 | "http://login.example.com/", |
| 10032 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10033 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10034 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10035 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10036 | // Pause on first read. |
| 10037 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 10038 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10039 | }; |
| 10040 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10041 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10042 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10043 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10044 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10045 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10046 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10048 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10049 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10052 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10055 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10056 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 10057 | // Host resolution takes |kTimeIncrement|. |
| 10058 | FastForwardBy(kTimeIncrement); |
| 10059 | // Resolving the current request with |ResolveNow| will cause the pending |
| 10060 | // request to instantly complete, and the async connect will start as well. |
| 10061 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 10062 | |
| 10063 | // Connecting takes |kTimeIncrement|. |
| 10064 | FastForwardBy(kTimeIncrement); |
| 10065 | data.RunUntilPaused(); |
| 10066 | |
| 10067 | FastForwardBy(kTimeIncrement); |
| 10068 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10069 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 10070 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10071 | } |
| 10072 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 10073 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10074 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10075 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10076 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10077 | |
| 10078 | HttpRequestInfo request; |
| 10079 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10080 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10081 | request.traffic_annotation = |
| 10082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10083 | |
| 10084 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10085 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10086 | "Host: www.example.org:443\r\n" |
| 10087 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10088 | }; |
| 10089 | |
| 10090 | MockRead data_reads[] = { |
| 10091 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 10092 | MockRead("Content-Length: 23\r\n\r\n"), |
| 10093 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10094 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10095 | }; |
| 10096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10097 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10098 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10099 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10103 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10106 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10107 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10108 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10110 | |
| 10111 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10112 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10113 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 10114 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10115 | } |
| 10116 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 10117 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10118 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10119 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10120 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10121 | |
| 10122 | HttpRequestInfo request; |
| 10123 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10124 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10125 | request.traffic_annotation = |
| 10126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10127 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10128 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10129 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10130 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10131 | spdy::SpdySerializedFrame rst( |
| 10132 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10133 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10134 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10135 | }; |
| 10136 | |
| 10137 | static const char* const kExtraHeaders[] = { |
| 10138 | "location", |
| 10139 | "http://login.example.com/", |
| 10140 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10141 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10142 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10143 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10144 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10145 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10146 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10147 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10148 | }; |
| 10149 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10150 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10151 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10152 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10153 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10157 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10158 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10160 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10161 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10162 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10164 | |
| 10165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10166 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10167 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 10168 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 10169 | } |
| 10170 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10171 | // Test the request-challenge-retry sequence for basic auth, through |
| 10172 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10173 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10174 | HttpRequestInfo request; |
| 10175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10176 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10177 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 10178 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10179 | request.traffic_annotation = |
| 10180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10181 | |
| 10182 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10183 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10184 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10185 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10186 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10187 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10189 | |
| 10190 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10191 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10192 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 10193 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10194 | spdy::SpdySerializedFrame rst( |
| 10195 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 10196 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10198 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10199 | // be issuing -- the final header line contains the credentials. |
| 10200 | const char* const kAuthCredentials[] = { |
| 10201 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 10202 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10203 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 10204 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 10205 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10206 | HostPortPair("www.example.org", 443))); |
| 10207 | // fetch https://www.example.org/ via HTTP |
| 10208 | const char get[] = |
| 10209 | "GET / HTTP/1.1\r\n" |
| 10210 | "Host: www.example.org\r\n" |
| 10211 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10212 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10213 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10214 | |
| 10215 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10216 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 10217 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10218 | }; |
| 10219 | |
| 10220 | // The proxy responds to the connect with a 407, using a persistent |
| 10221 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 10222 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10223 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10224 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 10225 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10226 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10227 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10228 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10229 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10230 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10231 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 10232 | "Content-Length: 5\r\n\r\n"; |
| 10233 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10234 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10235 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10236 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10237 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10238 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10239 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 10240 | CreateMockRead(conn_resp, 4, ASYNC), |
| 10241 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 10242 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10243 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10244 | }; |
| 10245 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10246 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10247 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10248 | // Negotiate SPDY to the proxy |
| 10249 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10250 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10251 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10252 | // Vanilla SSL to the server |
| 10253 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10255 | |
| 10256 | TestCompletionCallback callback1; |
| 10257 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10258 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10259 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10260 | |
| 10261 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10263 | |
| 10264 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10265 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 10266 | auto entries = log.GetEntries(); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10267 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10268 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10269 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10270 | ExpectLogContainsSomewhere( |
| 10271 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10272 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10273 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10274 | |
| 10275 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10276 | ASSERT_TRUE(response); |
| 10277 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10278 | EXPECT_EQ(407, response->headers->response_code()); |
| 10279 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10280 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 10281 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10282 | |
| 10283 | TestCompletionCallback callback2; |
| 10284 | |
| 10285 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10286 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10288 | |
| 10289 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10290 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10291 | |
| 10292 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10293 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10294 | |
| 10295 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10296 | EXPECT_EQ(200, response->headers->response_code()); |
| 10297 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10298 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10299 | |
| 10300 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10301 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10302 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10303 | LoadTimingInfo load_timing_info; |
| 10304 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10305 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10306 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10307 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10308 | trans.reset(); |
| 10309 | session->CloseAllConnections(); |
| 10310 | } |
| 10311 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10312 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10313 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10314 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10315 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10316 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10317 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10318 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10319 | HttpRequestInfo request; |
| 10320 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10321 | request.traffic_annotation = |
| 10322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10323 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10325 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10326 | push_request.method = "GET"; |
| 10327 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10328 | push_request.traffic_annotation = |
| 10329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10330 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10331 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10332 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10333 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10334 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10335 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10336 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10337 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10338 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10339 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10342 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10343 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10344 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10345 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10346 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10347 | |
| 10348 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10349 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10350 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10351 | }; |
| 10352 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10353 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10354 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10355 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10356 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10357 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10358 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10359 | spdy::SpdySerializedFrame stream1_body( |
| 10360 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10361 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10362 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10363 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10364 | |
| 10365 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10366 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10367 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10368 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10369 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10370 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10371 | }; |
| 10372 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10373 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10374 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10375 | // Negotiate SPDY to the proxy |
| 10376 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10377 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10378 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10379 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10380 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10381 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10382 | TestCompletionCallback callback; |
| 10383 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10385 | |
| 10386 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10388 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10389 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10390 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10391 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10392 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10394 | |
| 10395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10397 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10398 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10399 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10400 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10401 | |
| 10402 | EXPECT_EQ(200, response->headers->response_code()); |
| 10403 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10404 | |
| 10405 | std::string response_data; |
| 10406 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10407 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10408 | EXPECT_EQ("hello!", response_data); |
| 10409 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10410 | LoadTimingInfo load_timing_info; |
| 10411 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10412 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10413 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10414 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10415 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10416 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10417 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10418 | |
| 10419 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10421 | EXPECT_EQ("pushed", response_data); |
| 10422 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10423 | LoadTimingInfo push_load_timing_info; |
| 10424 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10425 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10426 | // The transactions should share a socket ID, despite being for different |
| 10427 | // origins. |
| 10428 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10429 | push_load_timing_info.socket_log_id); |
| 10430 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10431 | trans.reset(); |
| 10432 | push_trans.reset(); |
| 10433 | session->CloseAllConnections(); |
| 10434 | } |
| 10435 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10436 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10437 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10438 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10439 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10440 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10441 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10442 | HttpRequestInfo request; |
| 10443 | |
| 10444 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10445 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10446 | request.traffic_annotation = |
| 10447 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10448 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10449 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10450 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10451 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10452 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10453 | |
| 10454 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10455 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10456 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10457 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10458 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10459 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10460 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10461 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10462 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10463 | spdy::SpdySerializedFrame push_rst( |
| 10464 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10465 | |
| 10466 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10467 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10468 | }; |
| 10469 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10470 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10471 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10472 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10473 | spdy::SpdySerializedFrame stream1_body( |
| 10474 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10475 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10476 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10477 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10478 | |
| 10479 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10480 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10481 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10482 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10483 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10484 | }; |
| 10485 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10486 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10487 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10488 | // Negotiate SPDY to the proxy |
| 10489 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10490 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10492 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10493 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10494 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10495 | TestCompletionCallback callback; |
| 10496 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10498 | |
| 10499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10501 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10502 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10503 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10504 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10505 | |
| 10506 | EXPECT_EQ(200, response->headers->response_code()); |
| 10507 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10508 | |
| 10509 | std::string response_data; |
| 10510 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10511 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10512 | EXPECT_EQ("hello!", response_data); |
| 10513 | |
| 10514 | trans.reset(); |
| 10515 | session->CloseAllConnections(); |
| 10516 | } |
| 10517 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10518 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10519 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10520 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10521 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10522 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10523 | proxy_delegate->set_trusted_spdy_proxy( |
| 10524 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10525 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10526 | HttpRequestInfo request; |
| 10527 | |
| 10528 | request.method = "GET"; |
| 10529 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10530 | request.traffic_annotation = |
| 10531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10532 | |
| 10533 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10534 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10535 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10536 | BoundTestNetLog log; |
| 10537 | session_deps_.net_log = log.bound().net_log(); |
| 10538 | |
| 10539 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10540 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10541 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10542 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10544 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10545 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10546 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10547 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10548 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10549 | |
| 10550 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10551 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10552 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10553 | }; |
| 10554 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10555 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10556 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10557 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10558 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10559 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10560 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10561 | spdy::SpdySerializedFrame stream1_body( |
| 10562 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10563 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10564 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10565 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10566 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10567 | spdy::SpdySerializedFrame stream2_body( |
| 10568 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10569 | |
| 10570 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10571 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10572 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10573 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10574 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10575 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10576 | }; |
| 10577 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10578 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10579 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10580 | // Negotiate SPDY to the proxy |
| 10581 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10582 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10584 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10585 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10586 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10587 | TestCompletionCallback callback; |
| 10588 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10590 | |
| 10591 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10593 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10594 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10595 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10596 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10597 | |
| 10598 | EXPECT_EQ(200, response->headers->response_code()); |
| 10599 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10600 | |
| 10601 | std::string response_data; |
| 10602 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10603 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10604 | EXPECT_EQ("hello!", response_data); |
| 10605 | |
| 10606 | trans.reset(); |
| 10607 | session->CloseAllConnections(); |
| 10608 | } |
| 10609 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10610 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10611 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10612 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10613 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10614 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10615 | |
| 10616 | HttpRequestInfo request; |
| 10617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10618 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10619 | request.traffic_annotation = |
| 10620 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10621 | |
| 10622 | // Attempt to fetch the URL from a server with a bad cert |
| 10623 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10624 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10625 | "Host: www.example.org:443\r\n" |
| 10626 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10627 | }; |
| 10628 | |
| 10629 | MockRead bad_cert_reads[] = { |
| 10630 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10631 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10632 | }; |
| 10633 | |
| 10634 | // Attempt to fetch the URL with a good cert |
| 10635 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10636 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10637 | "Host: www.example.org:443\r\n" |
| 10638 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10639 | MockWrite("GET / HTTP/1.1\r\n" |
| 10640 | "Host: www.example.org\r\n" |
| 10641 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10642 | }; |
| 10643 | |
| 10644 | MockRead good_cert_reads[] = { |
| 10645 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10646 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10647 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10648 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10649 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10650 | }; |
| 10651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10652 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10653 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10654 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10655 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10656 | |
| 10657 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10659 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10661 | |
| 10662 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10665 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10667 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10671 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10672 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10674 | |
| 10675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10676 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10678 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10680 | |
| 10681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10682 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10684 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10685 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10686 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10687 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10688 | } |
| 10689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10690 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10691 | HttpRequestInfo request; |
| 10692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10694 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10695 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10696 | request.traffic_annotation = |
| 10697 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10701 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10702 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10703 | MockWrite( |
| 10704 | "GET / HTTP/1.1\r\n" |
| 10705 | "Host: www.example.org\r\n" |
| 10706 | "Connection: keep-alive\r\n" |
| 10707 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10708 | }; |
| 10709 | |
| 10710 | // Lastly, the server responds with the actual content. |
| 10711 | MockRead data_reads[] = { |
| 10712 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10713 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10714 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10715 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10716 | }; |
| 10717 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10718 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10721 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10722 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10725 | |
| 10726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10728 | } |
| 10729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10730 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10731 | // Test user agent values, used both for the request header of the original |
| 10732 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10733 | // no request header / no HttpUserAgentSettings object. |
| 10734 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10735 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10736 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10737 | if (!setting_user_agent) { |
| 10738 | session_deps_.http_user_agent_settings.reset(); |
| 10739 | } else { |
| 10740 | session_deps_.http_user_agent_settings = |
| 10741 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10742 | std::string() /* accept-language */, setting_user_agent); |
| 10743 | } |
| 10744 | session_deps_.proxy_resolution_service = |
| 10745 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10746 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10747 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10748 | for (const char* request_user_agent : kTestUserAgents) { |
| 10749 | HttpRequestInfo request; |
| 10750 | request.method = "GET"; |
| 10751 | request.url = GURL("https://www.example.org/"); |
| 10752 | if (request_user_agent) { |
| 10753 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10754 | request_user_agent); |
| 10755 | } |
| 10756 | request.traffic_annotation = |
| 10757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10758 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10760 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10761 | std::string expected_request; |
| 10762 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10763 | expected_request = |
| 10764 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10765 | "Host: www.example.org:443\r\n" |
| 10766 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10767 | } else { |
| 10768 | expected_request = base::StringPrintf( |
| 10769 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10770 | "Host: www.example.org:443\r\n" |
| 10771 | "Proxy-Connection: keep-alive\r\n" |
| 10772 | "User-Agent: %s\r\n\r\n", |
| 10773 | setting_user_agent); |
| 10774 | } |
| 10775 | MockWrite data_writes[] = { |
| 10776 | MockWrite(expected_request.c_str()), |
| 10777 | }; |
| 10778 | MockRead data_reads[] = { |
| 10779 | // Return an error, so the transaction stops here (this test isn't |
| 10780 | // interested in the rest). |
| 10781 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10782 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10783 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10784 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10785 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10786 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10788 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10789 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10790 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10791 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10793 | |
| 10794 | rv = callback.WaitForResult(); |
| 10795 | EXPECT_THAT(rv, IsOk()); |
| 10796 | } |
| 10797 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10798 | } |
| 10799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10800 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10801 | HttpRequestInfo request; |
| 10802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10803 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10804 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10805 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10806 | request.traffic_annotation = |
| 10807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10811 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10812 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10813 | MockWrite( |
| 10814 | "GET / HTTP/1.1\r\n" |
| 10815 | "Host: www.example.org\r\n" |
| 10816 | "Connection: keep-alive\r\n" |
| 10817 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10818 | }; |
| 10819 | |
| 10820 | // Lastly, the server responds with the actual content. |
| 10821 | MockRead data_reads[] = { |
| 10822 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10823 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10824 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10826 | }; |
| 10827 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10828 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10829 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10831 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10832 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10833 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10835 | |
| 10836 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10838 | } |
| 10839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10840 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10841 | HttpRequestInfo request; |
| 10842 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10843 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10844 | request.traffic_annotation = |
| 10845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10849 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10850 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10851 | MockWrite( |
| 10852 | "POST / HTTP/1.1\r\n" |
| 10853 | "Host: www.example.org\r\n" |
| 10854 | "Connection: keep-alive\r\n" |
| 10855 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10856 | }; |
| 10857 | |
| 10858 | // Lastly, the server responds with the actual content. |
| 10859 | MockRead data_reads[] = { |
| 10860 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10861 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10862 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10863 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10864 | }; |
| 10865 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10866 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10867 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10869 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10870 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10871 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10873 | |
| 10874 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10876 | } |
| 10877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10878 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10879 | HttpRequestInfo request; |
| 10880 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10881 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10882 | request.traffic_annotation = |
| 10883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10884 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10886 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10887 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10888 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10889 | MockWrite( |
| 10890 | "PUT / HTTP/1.1\r\n" |
| 10891 | "Host: www.example.org\r\n" |
| 10892 | "Connection: keep-alive\r\n" |
| 10893 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10894 | }; |
| 10895 | |
| 10896 | // Lastly, the server responds with the actual content. |
| 10897 | MockRead data_reads[] = { |
| 10898 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10899 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10900 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10901 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10902 | }; |
| 10903 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10904 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10905 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10907 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10908 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10909 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10911 | |
| 10912 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10914 | } |
| 10915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10916 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10917 | HttpRequestInfo request; |
| 10918 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10919 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10920 | request.traffic_annotation = |
| 10921 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10925 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10926 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10927 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10928 | "Host: www.example.org\r\n" |
| 10929 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10930 | }; |
| 10931 | |
| 10932 | // Lastly, the server responds with the actual content. |
| 10933 | MockRead data_reads[] = { |
| 10934 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10935 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10936 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10937 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10938 | }; |
| 10939 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10940 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10943 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10944 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10947 | |
| 10948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10950 | } |
| 10951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10952 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10953 | HttpRequestInfo request; |
| 10954 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10955 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10956 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10957 | request.traffic_annotation = |
| 10958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10961 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10962 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10963 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10964 | MockWrite( |
| 10965 | "GET / HTTP/1.1\r\n" |
| 10966 | "Host: www.example.org\r\n" |
| 10967 | "Connection: keep-alive\r\n" |
| 10968 | "Pragma: no-cache\r\n" |
| 10969 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10970 | }; |
| 10971 | |
| 10972 | // Lastly, the server responds with the actual content. |
| 10973 | MockRead data_reads[] = { |
| 10974 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10975 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10976 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10978 | }; |
| 10979 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10980 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10983 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10984 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 10985 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10987 | |
| 10988 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10990 | } |
| 10991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10992 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10993 | HttpRequestInfo request; |
| 10994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10995 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10996 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10997 | request.traffic_annotation = |
| 10998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10999 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11002 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11003 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11004 | MockWrite( |
| 11005 | "GET / HTTP/1.1\r\n" |
| 11006 | "Host: www.example.org\r\n" |
| 11007 | "Connection: keep-alive\r\n" |
| 11008 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11009 | }; |
| 11010 | |
| 11011 | // Lastly, the server responds with the actual content. |
| 11012 | MockRead data_reads[] = { |
| 11013 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11014 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11015 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11016 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11017 | }; |
| 11018 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11019 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11022 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11023 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11024 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11026 | |
| 11027 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11028 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11029 | } |
| 11030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11031 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11032 | HttpRequestInfo request; |
| 11033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11034 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11035 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11036 | request.traffic_annotation = |
| 11037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11041 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11042 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11043 | MockWrite( |
| 11044 | "GET / HTTP/1.1\r\n" |
| 11045 | "Host: www.example.org\r\n" |
| 11046 | "Connection: keep-alive\r\n" |
| 11047 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11048 | }; |
| 11049 | |
| 11050 | // Lastly, the server responds with the actual content. |
| 11051 | MockRead data_reads[] = { |
| 11052 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11054 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11055 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11056 | }; |
| 11057 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11058 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11060 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11061 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11062 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11063 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11065 | |
| 11066 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11067 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 11068 | } |
| 11069 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11070 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11071 | HttpRequestInfo request; |
| 11072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11073 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 11074 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 11075 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 11076 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11077 | request.traffic_annotation = |
| 11078 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11081 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11082 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11083 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11084 | MockWrite( |
| 11085 | "GET / HTTP/1.1\r\n" |
| 11086 | "Host: www.example.org\r\n" |
| 11087 | "Connection: keep-alive\r\n" |
| 11088 | "referer: www.foo.com\r\n" |
| 11089 | "hEllo: Kitty\r\n" |
| 11090 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11091 | }; |
| 11092 | |
| 11093 | // Lastly, the server responds with the actual content. |
| 11094 | MockRead data_reads[] = { |
| 11095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11096 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11097 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11098 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11099 | }; |
| 11100 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11101 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11104 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11105 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11106 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11108 | |
| 11109 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 11111 | } |
| 11112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11113 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11114 | HttpRequestInfo request; |
| 11115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11116 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11117 | request.traffic_annotation = |
| 11118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11119 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11120 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11121 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11122 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11123 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11124 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11125 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11127 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11128 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11129 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11130 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11131 | |
| 11132 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11133 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11134 | MockWrite("GET / HTTP/1.1\r\n" |
| 11135 | "Host: www.example.org\r\n" |
| 11136 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11137 | |
| 11138 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11139 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11140 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11141 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11142 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11143 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11144 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11147 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11148 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11149 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11150 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11151 | |
| 11152 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11153 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11155 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11156 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11157 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11158 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11159 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11160 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11161 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11162 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11163 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11164 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11165 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11167 | EXPECT_EQ("Payload", response_text); |
| 11168 | } |
| 11169 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11170 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11171 | HttpRequestInfo request; |
| 11172 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11173 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11174 | request.traffic_annotation = |
| 11175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11176 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11177 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11178 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11179 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11180 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11181 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11182 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11183 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11184 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11185 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11186 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 11187 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11188 | |
| 11189 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11190 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11191 | base::size(write_buffer)), |
| 11192 | MockWrite("GET / HTTP/1.1\r\n" |
| 11193 | "Host: www.example.org\r\n" |
| 11194 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11195 | |
| 11196 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11197 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 11198 | base::size(read_buffer)), |
| 11199 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11200 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11201 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11202 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11203 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11205 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11206 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11207 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11209 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11210 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11211 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11213 | |
| 11214 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11215 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11216 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11217 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11218 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11219 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11220 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11223 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11224 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11225 | |
| 11226 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11227 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11229 | EXPECT_EQ("Payload", response_text); |
| 11230 | } |
| 11231 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11232 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11233 | HttpRequestInfo request; |
| 11234 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11235 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11236 | request.traffic_annotation = |
| 11237 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11238 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11239 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11240 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11241 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11242 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11243 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11244 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11246 | |
| 11247 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11248 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11249 | |
| 11250 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11251 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11252 | MockWrite("GET / HTTP/1.1\r\n" |
| 11253 | "Host: www.example.org\r\n" |
| 11254 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11255 | |
| 11256 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11257 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11258 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11259 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11260 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11261 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11262 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11263 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11264 | |
| 11265 | TestCompletionCallback callback; |
| 11266 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11267 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11268 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11269 | |
| 11270 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11271 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11273 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11274 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11275 | |
| 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 | TestLoadTimingNotReused(load_timing_info, |
| 11279 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11280 | |
| 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11284 | EXPECT_EQ("Payload", response_text); |
| 11285 | } |
| 11286 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11287 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11288 | HttpRequestInfo request; |
| 11289 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11290 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11291 | request.traffic_annotation = |
| 11292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11293 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11294 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11295 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11296 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11297 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11298 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11299 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11301 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11302 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11303 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11304 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11305 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11306 | 0x05, // Version |
| 11307 | 0x01, // Command (CONNECT) |
| 11308 | 0x00, // Reserved. |
| 11309 | 0x03, // Address type (DOMAINNAME). |
| 11310 | 0x0F, // Length of domain (15) |
| 11311 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11312 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11313 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11314 | const char kSOCKS5OkResponse[] = |
| 11315 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11316 | |
| 11317 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11318 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11319 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11320 | MockWrite("GET / HTTP/1.1\r\n" |
| 11321 | "Host: www.example.org\r\n" |
| 11322 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11323 | |
| 11324 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11325 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11326 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11327 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11328 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11329 | MockRead("Payload"), |
| 11330 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11331 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11332 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11334 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11335 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11336 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11337 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11339 | |
| 11340 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11342 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11343 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11344 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11345 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11346 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11347 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11348 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11349 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11350 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11351 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11352 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11353 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11355 | EXPECT_EQ("Payload", response_text); |
| 11356 | } |
| 11357 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11358 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11359 | HttpRequestInfo request; |
| 11360 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11361 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11362 | request.traffic_annotation = |
| 11363 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11364 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11365 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11366 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11367 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11368 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11369 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11373 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11374 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11375 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11376 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11377 | 0x05, // Version |
| 11378 | 0x01, // Command (CONNECT) |
| 11379 | 0x00, // Reserved. |
| 11380 | 0x03, // Address type (DOMAINNAME). |
| 11381 | 0x0F, // Length of domain (15) |
| 11382 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11383 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11384 | }; |
| 11385 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11386 | const char kSOCKS5OkResponse[] = |
| 11387 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11388 | |
| 11389 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11390 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11391 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11392 | base::size(kSOCKS5OkRequest)), |
| 11393 | MockWrite("GET / HTTP/1.1\r\n" |
| 11394 | "Host: www.example.org\r\n" |
| 11395 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11396 | |
| 11397 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11398 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11399 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11400 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11402 | MockRead("Payload"), |
| 11403 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11404 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11405 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11406 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11407 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11408 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11411 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11412 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11413 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11415 | |
| 11416 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11417 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11419 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11420 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11421 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11422 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11423 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11424 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11425 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11426 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11427 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11428 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11429 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11430 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11431 | EXPECT_EQ("Payload", response_text); |
| 11432 | } |
| 11433 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11434 | namespace { |
| 11435 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11436 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11437 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11438 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11439 | std::string proxy_server; |
| 11440 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11441 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11442 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11443 | }; |
| 11444 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11445 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11446 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11448 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11449 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11450 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11451 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11452 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11453 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11454 | url::SchemeHostPort("https", "host.with.alternate", 443), |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 11455 | NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11456 | |
| 11457 | return session; |
| 11458 | } |
| 11459 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11460 | int GroupIdTransactionHelper(const std::string& url, |
| 11461 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11462 | HttpRequestInfo request; |
| 11463 | request.method = "GET"; |
| 11464 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11465 | request.traffic_annotation = |
| 11466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11470 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11471 | |
| 11472 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11473 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11474 | } |
| 11475 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11476 | } // namespace |
| 11477 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11478 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11479 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11480 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11481 | "", // unused |
| 11482 | "http://www.example.org/direct", |
| 11483 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11484 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11485 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11486 | NetworkIsolationKey(), |
| 11487 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11488 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11489 | }, |
| 11490 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11491 | "", // unused |
| 11492 | "http://[2001:1418:13:1::25]/direct", |
| 11493 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11494 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11495 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11496 | NetworkIsolationKey(), |
| 11497 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11498 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11499 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11500 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11501 | // SSL Tests |
| 11502 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11503 | "", // unused |
| 11504 | "https://www.example.org/direct_ssl", |
| 11505 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11506 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11507 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11508 | NetworkIsolationKey(), |
| 11509 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11510 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11511 | }, |
| 11512 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11513 | "", // unused |
| 11514 | "https://[2001:1418:13:1::25]/direct", |
| 11515 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11516 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11517 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11518 | NetworkIsolationKey(), |
| 11519 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11520 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11521 | }, |
| 11522 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11523 | "", // unused |
| 11524 | "https://host.with.alternate/direct", |
| 11525 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11526 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11527 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11528 | NetworkIsolationKey(), |
| 11529 | false /* disable_secure_dns */), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11530 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11531 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11532 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11533 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11534 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11535 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11536 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11537 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11538 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11539 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11540 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11541 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11542 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11543 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11544 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11545 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11546 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11547 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11548 | |
| 11549 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11550 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11551 | EXPECT_EQ(tests[i].expected_group_id, |
| 11552 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11553 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11554 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11555 | } |
| 11556 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11557 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11558 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11559 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11560 | "http_proxy", |
| 11561 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11562 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11563 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11564 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11565 | NetworkIsolationKey(), |
| 11566 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11567 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11568 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11569 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11570 | // SSL Tests |
| 11571 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11572 | "http_proxy", |
| 11573 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11574 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11575 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11576 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11577 | NetworkIsolationKey(), |
| 11578 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11579 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11580 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11581 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11582 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11583 | "http_proxy", |
| 11584 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11585 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11586 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11587 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11588 | NetworkIsolationKey(), |
| 11589 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11590 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11591 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11592 | }; |
| 11593 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11594 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11595 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11596 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11597 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11598 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11599 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11600 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11601 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11602 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11603 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11604 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11605 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11606 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11607 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11608 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11609 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11610 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11611 | |
| 11612 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11613 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11614 | EXPECT_EQ(tests[i].expected_group_id, |
| 11615 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11616 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11617 | } |
| 11618 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11619 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11620 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11621 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11622 | "socks4://socks_proxy:1080", |
| 11623 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11624 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11625 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11626 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11627 | NetworkIsolationKey(), |
| 11628 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11629 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11630 | }, |
| 11631 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11632 | "socks5://socks_proxy:1080", |
| 11633 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11634 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11635 | ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11636 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11637 | NetworkIsolationKey(), |
| 11638 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11639 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11640 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11641 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11642 | // SSL Tests |
| 11643 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11644 | "socks4://socks_proxy:1080", |
| 11645 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11646 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11647 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11648 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11649 | NetworkIsolationKey(), |
| 11650 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11651 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11652 | }, |
| 11653 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11654 | "socks5://socks_proxy:1080", |
| 11655 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11656 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11657 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11658 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11659 | NetworkIsolationKey(), |
| 11660 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11661 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11662 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11663 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11664 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11665 | "socks4://socks_proxy:1080", |
| 11666 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11667 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11668 | ClientSocketPool::SocketType::kSsl, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 11669 | PrivacyMode::PRIVACY_MODE_DISABLED, |
| 11670 | NetworkIsolationKey(), |
| 11671 | false /* disable_secure_dns */), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11672 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11673 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11674 | }; |
| 11675 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11676 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11677 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11678 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11679 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11680 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11681 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11682 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11683 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11684 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11685 | ProxyServer proxy_server( |
| 11686 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11687 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11688 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11689 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11690 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11691 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11692 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11693 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11696 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11697 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11698 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11699 | EXPECT_EQ(tests[i].expected_group_id, |
| 11700 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11701 | } |
| 11702 | } |
| 11703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11704 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11705 | HttpRequestInfo request; |
| 11706 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11707 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11708 | request.traffic_annotation = |
| 11709 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11710 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11711 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11712 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11713 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11714 | // This simulates failure resolving all hostnames; that means we will fail |
| 11715 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11716 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11721 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11722 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11725 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11727 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11728 | } |
| 11729 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11730 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11731 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11732 | HttpRequestInfo request; |
| 11733 | request.method = "GET"; |
| 11734 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11735 | request.traffic_annotation = |
| 11736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11737 | |
| 11738 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11739 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11740 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11741 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11744 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11745 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11747 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11748 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11749 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11751 | |
| 11752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11753 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11754 | |
| 11755 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11756 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11757 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11758 | } |
| 11759 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11760 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11761 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11762 | HttpRequestInfo request; |
| 11763 | request.method = "GET"; |
| 11764 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11765 | request.traffic_annotation = |
| 11766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11767 | |
| 11768 | MockRead data_reads[] = { |
| 11769 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11771 | }; |
| 11772 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11773 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11777 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11779 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11780 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11781 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11783 | |
| 11784 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11785 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11787 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11788 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11789 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11790 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11791 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11792 | |
| 11793 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11794 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11795 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11796 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11797 | |
| 11798 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11799 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11800 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11801 | } |
| 11802 | |
| 11803 | // Make sure that a dropped connection while draining the body for auth |
| 11804 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11805 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11806 | HttpRequestInfo request; |
| 11807 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11808 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11809 | request.traffic_annotation = |
| 11810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11811 | |
| 11812 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11813 | MockWrite( |
| 11814 | "GET / HTTP/1.1\r\n" |
| 11815 | "Host: www.example.org\r\n" |
| 11816 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11817 | }; |
| 11818 | |
| 11819 | MockRead data_reads1[] = { |
| 11820 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11821 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11822 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11823 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11824 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11825 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11826 | }; |
| 11827 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11828 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11829 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11831 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11832 | // be issuing -- the final header line contains the credentials. |
| 11833 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11834 | MockWrite( |
| 11835 | "GET / HTTP/1.1\r\n" |
| 11836 | "Host: www.example.org\r\n" |
| 11837 | "Connection: keep-alive\r\n" |
| 11838 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11839 | }; |
| 11840 | |
| 11841 | // Lastly, the server responds with the actual content. |
| 11842 | MockRead data_reads2[] = { |
| 11843 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11845 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11847 | }; |
| 11848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11849 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11850 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11853 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11854 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11856 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11857 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11859 | |
| 11860 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11861 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11862 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11863 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11864 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11865 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11867 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11869 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11871 | |
| 11872 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11873 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11875 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11876 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11877 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11878 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11879 | } |
| 11880 | |
| 11881 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11882 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11883 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11884 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11885 | |
| 11886 | HttpRequestInfo request; |
| 11887 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11888 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11889 | request.traffic_annotation = |
| 11890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11891 | |
| 11892 | MockRead proxy_reads[] = { |
| 11893 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11894 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11895 | }; |
| 11896 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11897 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11898 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11899 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11903 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11904 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11905 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11909 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11910 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11912 | |
| 11913 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11914 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11915 | } |
| 11916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11917 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11918 | HttpRequestInfo request; |
| 11919 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11920 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11921 | request.traffic_annotation = |
| 11922 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11923 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11924 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11925 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11926 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11927 | MockRead data_reads[] = { |
| 11928 | 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] | 11929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11930 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11931 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11932 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11933 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11935 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11936 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11937 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11939 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11940 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11942 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11943 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11944 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11945 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11946 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11947 | |
| 11948 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11949 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11950 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11951 | } |
| 11952 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11953 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11954 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11955 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11956 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11957 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11958 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11960 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11961 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11962 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11963 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11964 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11965 | |
| 11966 | HttpRequestInfo request; |
| 11967 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11968 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11969 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11970 | request.traffic_annotation = |
| 11971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11972 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11974 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11975 | |
| 11976 | MockRead data_reads[] = { |
| 11977 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11978 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11979 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11981 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11984 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11985 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 11986 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11988 | |
| 11989 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11990 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11992 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11993 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11994 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11995 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11996 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11997 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11998 | } |
| 11999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12000 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 12001 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 12002 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12003 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 12004 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 12005 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 12006 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 12007 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12009 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12010 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12011 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 12012 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12013 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12014 | |
| 12015 | HttpRequestInfo request; |
| 12016 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12017 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12018 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12019 | request.traffic_annotation = |
| 12020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 12021 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 12022 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12023 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12024 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12025 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12026 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12027 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12028 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12029 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12030 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12031 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12033 | |
| 12034 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12035 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12036 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 12037 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 12038 | } |
| 12039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12040 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12041 | class FakeUploadElementReader : public UploadElementReader { |
| 12042 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12043 | FakeUploadElementReader() = default; |
| 12044 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12045 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12046 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12047 | |
| 12048 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12049 | int Init(CompletionOnceCallback callback) override { |
| 12050 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12051 | return ERR_IO_PENDING; |
| 12052 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 12053 | uint64_t GetContentLength() const override { return 0; } |
| 12054 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12055 | int Read(IOBuffer* buf, |
| 12056 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12057 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12058 | return ERR_FAILED; |
| 12059 | } |
| 12060 | |
| 12061 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12062 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12063 | }; |
| 12064 | |
| 12065 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12066 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 12067 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12068 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12069 | |
| 12070 | HttpRequestInfo request; |
| 12071 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12072 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12073 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12074 | request.traffic_annotation = |
| 12075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12078 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12079 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12080 | |
| 12081 | StaticSocketDataProvider data; |
| 12082 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12083 | |
| 12084 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12085 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12087 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12088 | |
| 12089 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12090 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 12091 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12092 | |
| 12093 | // Return Init()'s result after the transaction gets destroyed. |
| 12094 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 12095 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 12096 | } |
| 12097 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12098 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12099 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12100 | HttpRequestInfo request; |
| 12101 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12102 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12103 | request.traffic_annotation = |
| 12104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12105 | |
| 12106 | // First transaction will request a resource and receive a Basic challenge |
| 12107 | // with realm="first_realm". |
| 12108 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12109 | MockWrite( |
| 12110 | "GET / HTTP/1.1\r\n" |
| 12111 | "Host: www.example.org\r\n" |
| 12112 | "Connection: keep-alive\r\n" |
| 12113 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12114 | }; |
| 12115 | MockRead data_reads1[] = { |
| 12116 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12117 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 12118 | "\r\n"), |
| 12119 | }; |
| 12120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12121 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12122 | // for first_realm. The server will reject and provide a challenge with |
| 12123 | // second_realm. |
| 12124 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12125 | MockWrite( |
| 12126 | "GET / HTTP/1.1\r\n" |
| 12127 | "Host: www.example.org\r\n" |
| 12128 | "Connection: keep-alive\r\n" |
| 12129 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 12130 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12131 | }; |
| 12132 | MockRead data_reads2[] = { |
| 12133 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12134 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 12135 | "\r\n"), |
| 12136 | }; |
| 12137 | |
| 12138 | // This again fails, and goes back to first_realm. Make sure that the |
| 12139 | // entry is removed from cache. |
| 12140 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12141 | MockWrite( |
| 12142 | "GET / HTTP/1.1\r\n" |
| 12143 | "Host: www.example.org\r\n" |
| 12144 | "Connection: keep-alive\r\n" |
| 12145 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 12146 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12147 | }; |
| 12148 | MockRead data_reads3[] = { |
| 12149 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 12150 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 12151 | "\r\n"), |
| 12152 | }; |
| 12153 | |
| 12154 | // Try one last time (with the correct password) and get the resource. |
| 12155 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12156 | MockWrite( |
| 12157 | "GET / HTTP/1.1\r\n" |
| 12158 | "Host: www.example.org\r\n" |
| 12159 | "Connection: keep-alive\r\n" |
| 12160 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 12161 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12162 | }; |
| 12163 | MockRead data_reads4[] = { |
| 12164 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12165 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12166 | "Content-Length: 5\r\n" |
| 12167 | "\r\n" |
| 12168 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12169 | }; |
| 12170 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12171 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 12172 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 12173 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 12174 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12175 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12176 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 12177 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 12178 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12180 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12181 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12183 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12184 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12185 | // Issue the first request with Authorize headers. There should be a |
| 12186 | // password prompt for first_realm waiting to be filled in after the |
| 12187 | // transaction completes. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12188 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12190 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12191 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12192 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12193 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12194 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12195 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12196 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12197 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12198 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12199 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12200 | |
| 12201 | // Issue the second request with an incorrect password. There should be a |
| 12202 | // password prompt for second_realm waiting to be filled in after the |
| 12203 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12204 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12205 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 12206 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12208 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12209 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12210 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12211 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12212 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12213 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12214 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12215 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12216 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12217 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12218 | |
| 12219 | // Issue the third request with another incorrect password. There should be |
| 12220 | // a password prompt for first_realm waiting to be filled in. If the password |
| 12221 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 12222 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12223 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12224 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 12225 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12227 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12228 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12229 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12230 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12231 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12232 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12233 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 12234 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 12235 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 12236 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12237 | |
| 12238 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12239 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12240 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 12241 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12243 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12244 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12245 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12246 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 12247 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12248 | } |
| 12249 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12250 | // Regression test for https://crbug.com/754395. |
| 12251 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12252 | MockRead data_reads[] = { |
| 12253 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12254 | MockRead(kAlternativeServiceHttpHeader), |
| 12255 | MockRead("\r\n"), |
| 12256 | MockRead("hello world"), |
| 12257 | MockRead(SYNCHRONOUS, OK), |
| 12258 | }; |
| 12259 | |
| 12260 | HttpRequestInfo request; |
| 12261 | request.method = "GET"; |
| 12262 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12263 | request.traffic_annotation = |
| 12264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12266 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12267 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12268 | |
| 12269 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12270 | ssl.ssl_info.cert = |
| 12271 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12272 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12273 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12275 | |
| 12276 | TestCompletionCallback callback; |
| 12277 | |
| 12278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12279 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12280 | |
| 12281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12283 | |
| 12284 | url::SchemeHostPort test_server(request.url); |
| 12285 | HttpServerProperties* http_server_properties = |
| 12286 | session->http_server_properties(); |
| 12287 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12288 | http_server_properties |
| 12289 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12290 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12291 | |
| 12292 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12293 | |
| 12294 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12295 | ASSERT_TRUE(response); |
| 12296 | ASSERT_TRUE(response->headers); |
| 12297 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12298 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12299 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12300 | |
| 12301 | std::string response_data; |
| 12302 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12303 | EXPECT_EQ("hello world", response_data); |
| 12304 | |
| 12305 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12306 | http_server_properties |
| 12307 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12308 | .empty()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12309 | } |
| 12310 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12311 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12312 | MockRead data_reads[] = { |
| 12313 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12314 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12315 | MockRead("\r\n"), |
| 12316 | MockRead("hello world"), |
| 12317 | MockRead(SYNCHRONOUS, OK), |
| 12318 | }; |
| 12319 | |
| 12320 | HttpRequestInfo request; |
| 12321 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12322 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12323 | request.traffic_annotation = |
| 12324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12325 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12326 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12328 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12329 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12330 | ssl.ssl_info.cert = |
| 12331 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12332 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12334 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12335 | TestCompletionCallback callback; |
| 12336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12339 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12340 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12342 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12343 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12344 | HttpServerProperties* http_server_properties = |
| 12345 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12346 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12347 | http_server_properties |
| 12348 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12349 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12350 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12351 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12353 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12354 | ASSERT_TRUE(response); |
| 12355 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12356 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12357 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12358 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12359 | |
| 12360 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12361 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12362 | EXPECT_EQ("hello world", response_data); |
| 12363 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12364 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12365 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12366 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12367 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12368 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12369 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12370 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12371 | } |
| 12372 | |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12373 | TEST_F(HttpNetworkTransactionTest, |
| 12374 | HonorAlternativeServiceHeaderWithNetworkIsolationKey) { |
| 12375 | base::test::ScopedFeatureList feature_list; |
| 12376 | feature_list.InitWithFeatures( |
| 12377 | // enabled_features |
| 12378 | {features::kPartitionHttpServerPropertiesByNetworkIsolationKey, |
| 12379 | // Need to partition connections by NetworkIsolationKey for |
| 12380 | // SpdySessionKeys to include NetworkIsolationKeys. |
| 12381 | features::kPartitionConnectionsByNetworkIsolationKey}, |
| 12382 | // disabled_features |
| 12383 | {}); |
| 12384 | // Since HttpServerProperties caches the feature value, have to create a new |
| 12385 | // one. |
| 12386 | session_deps_.http_server_properties = |
| 12387 | std::make_unique<HttpServerProperties>(); |
| 12388 | |
| 12389 | const url::Origin kOrigin1 = url::Origin::Create(GURL("https://foo.test/")); |
| 12390 | const net::NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 12391 | const url::Origin kOrigin2 = url::Origin::Create(GURL("https://bar.test/")); |
| 12392 | const net::NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
| 12393 | |
| 12394 | MockRead data_reads[] = { |
| 12395 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12396 | MockRead(kAlternativeServiceHttpHeader), |
| 12397 | MockRead("\r\n"), |
| 12398 | MockRead("hello world"), |
| 12399 | MockRead(SYNCHRONOUS, OK), |
| 12400 | }; |
| 12401 | |
| 12402 | HttpRequestInfo request; |
| 12403 | request.method = "GET"; |
| 12404 | request.url = GURL("https://www.example.org/"); |
| 12405 | request.traffic_annotation = |
| 12406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12407 | request.network_isolation_key = kNetworkIsolationKey1; |
| 12408 | |
| 12409 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 12410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12411 | |
| 12412 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12413 | ssl.ssl_info.cert = |
| 12414 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12415 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12417 | |
| 12418 | TestCompletionCallback callback; |
| 12419 | |
| 12420 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12421 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12422 | |
| 12423 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12425 | |
| 12426 | url::SchemeHostPort test_server(request.url); |
| 12427 | HttpServerProperties* http_server_properties = |
| 12428 | session->http_server_properties(); |
| 12429 | EXPECT_TRUE( |
| 12430 | http_server_properties |
| 12431 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey1) |
| 12432 | .empty()); |
| 12433 | |
| 12434 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12435 | |
| 12436 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12437 | ASSERT_TRUE(response); |
| 12438 | ASSERT_TRUE(response->headers); |
| 12439 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12440 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12441 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12442 | |
| 12443 | std::string response_data; |
| 12444 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12445 | EXPECT_EQ("hello world", response_data); |
| 12446 | |
| 12447 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12448 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12449 | kNetworkIsolationKey1); |
| 12450 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12451 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12452 | EXPECT_EQ(alternative_service, |
| 12453 | alternative_service_info_vector[0].alternative_service()); |
| 12454 | |
| 12455 | // Make sure the alternative service information is only associated with |
| 12456 | // kNetworkIsolationKey1. |
| 12457 | EXPECT_TRUE( |
| 12458 | http_server_properties |
| 12459 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12460 | .empty()); |
| 12461 | EXPECT_TRUE( |
| 12462 | http_server_properties |
| 12463 | ->GetAlternativeServiceInfos(test_server, kNetworkIsolationKey2) |
| 12464 | .empty()); |
| 12465 | } |
| 12466 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12467 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12468 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12469 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12470 | MockRead data_reads[] = { |
| 12471 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12472 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12473 | MockRead("\r\n"), |
| 12474 | MockRead("hello world"), |
| 12475 | MockRead(SYNCHRONOUS, OK), |
| 12476 | }; |
| 12477 | |
| 12478 | HttpRequestInfo request; |
| 12479 | request.method = "GET"; |
| 12480 | request.url = GURL("http://www.example.org/"); |
| 12481 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12482 | request.traffic_annotation = |
| 12483 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12484 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12485 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12486 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12487 | |
| 12488 | TestCompletionCallback callback; |
| 12489 | |
| 12490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12491 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12492 | |
| 12493 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12494 | HttpServerProperties* http_server_properties = |
| 12495 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12496 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12497 | http_server_properties |
| 12498 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12499 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12500 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12503 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12505 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12506 | ASSERT_TRUE(response); |
| 12507 | ASSERT_TRUE(response->headers); |
| 12508 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12509 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12510 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12511 | |
| 12512 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12513 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12514 | EXPECT_EQ("hello world", response_data); |
| 12515 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12516 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12517 | http_server_properties |
| 12518 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12519 | .empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12520 | } |
| 12521 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12522 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12523 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12524 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12525 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12526 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12527 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12528 | HttpRequestInfo request; |
| 12529 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12530 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12531 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12532 | request.traffic_annotation = |
| 12533 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12534 | |
| 12535 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12536 | StaticSocketDataProvider first_data; |
| 12537 | first_data.set_connect_data(mock_connect); |
| 12538 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12539 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12540 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12542 | |
| 12543 | MockRead data_reads[] = { |
| 12544 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12545 | MockRead(ASYNC, OK), |
| 12546 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12547 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12548 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12549 | |
| 12550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12551 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12552 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12553 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12554 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12555 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12556 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12557 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12558 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 12559 | alternative_service, expiration); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12562 | TestCompletionCallback callback; |
| 12563 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12564 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12565 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12566 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12567 | } |
| 12568 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12569 | // Regression test for https://crbug.com/615497: |
| 12570 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12571 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12572 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12573 | HttpRequestInfo request; |
| 12574 | request.method = "GET"; |
| 12575 | request.url = GURL("http://www.example.org/"); |
| 12576 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12577 | request.traffic_annotation = |
| 12578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12579 | |
| 12580 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12581 | StaticSocketDataProvider first_data; |
| 12582 | first_data.set_connect_data(mock_connect); |
| 12583 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12584 | |
| 12585 | MockRead data_reads[] = { |
| 12586 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12587 | MockRead(ASYNC, OK), |
| 12588 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12589 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12590 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12591 | |
| 12592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12593 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12594 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12595 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12596 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12597 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12598 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12599 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 12600 | alternative_service, expiration); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12603 | TestCompletionCallback callback; |
| 12604 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12605 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12606 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12607 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12608 | } |
| 12609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12610 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12611 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12613 | HttpServerProperties* http_server_properties = |
| 12614 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12615 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12616 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12617 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12618 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12619 | test_server, NetworkIsolationKey(), alternative_service, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12620 | session->params().quic_params.supported_versions); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12621 | EXPECT_EQ(1u, |
| 12622 | http_server_properties |
| 12623 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12624 | .size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12625 | |
| 12626 | // Send a clear header. |
| 12627 | MockRead data_reads[] = { |
| 12628 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12629 | MockRead("Alt-Svc: clear\r\n"), |
| 12630 | MockRead("\r\n"), |
| 12631 | MockRead("hello world"), |
| 12632 | MockRead(SYNCHRONOUS, OK), |
| 12633 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12634 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12636 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12637 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12638 | ssl.ssl_info.cert = |
| 12639 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12640 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12642 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12643 | HttpRequestInfo request; |
| 12644 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12645 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12646 | request.traffic_annotation = |
| 12647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12648 | |
| 12649 | TestCompletionCallback callback; |
| 12650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12652 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12653 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12654 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12656 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12657 | ASSERT_TRUE(response); |
| 12658 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12659 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12660 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12661 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12662 | |
| 12663 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12664 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12665 | EXPECT_EQ("hello world", response_data); |
| 12666 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12667 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12668 | http_server_properties |
| 12669 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12670 | .empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12671 | } |
| 12672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12673 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12674 | MockRead data_reads[] = { |
| 12675 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12676 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12677 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12678 | MockRead("hello world"), |
| 12679 | MockRead(SYNCHRONOUS, OK), |
| 12680 | }; |
| 12681 | |
| 12682 | HttpRequestInfo request; |
| 12683 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12684 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12685 | request.traffic_annotation = |
| 12686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12687 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12688 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12690 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12691 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12692 | ssl.ssl_info.cert = |
| 12693 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12694 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12696 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12697 | TestCompletionCallback callback; |
| 12698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12701 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12704 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12705 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12706 | HttpServerProperties* http_server_properties = |
| 12707 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12708 | EXPECT_TRUE( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12709 | http_server_properties |
| 12710 | ->GetAlternativeServiceInfos(test_server, NetworkIsolationKey()) |
| 12711 | .empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12712 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12713 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12715 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12716 | ASSERT_TRUE(response); |
| 12717 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12718 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12719 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12720 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12721 | |
| 12722 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12723 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12724 | EXPECT_EQ("hello world", response_data); |
| 12725 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12726 | AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12727 | http_server_properties->GetAlternativeServiceInfos(test_server, |
| 12728 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12729 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12730 | |
| 12731 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12732 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12733 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12734 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12735 | 1234); |
| 12736 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12737 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12738 | } |
| 12739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12740 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12741 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12742 | HostPortPair alternative("alternative.example.org", 443); |
| 12743 | std::string origin_url = "https://origin.example.org:443"; |
| 12744 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12745 | |
| 12746 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12747 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12748 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12750 | |
| 12751 | // HTTP/1.1 data for request. |
| 12752 | MockWrite http_writes[] = { |
| 12753 | MockWrite("GET / HTTP/1.1\r\n" |
| 12754 | "Host: alternative.example.org\r\n" |
| 12755 | "Connection: keep-alive\r\n\r\n"), |
| 12756 | }; |
| 12757 | |
| 12758 | MockRead http_reads[] = { |
| 12759 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12760 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12761 | "Content-Length: 40\r\n\r\n" |
| 12762 | "first HTTP/1.1 response from alternative"), |
| 12763 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12764 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12765 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12766 | |
| 12767 | StaticSocketDataProvider data_refused; |
| 12768 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12769 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12770 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12771 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12773 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12774 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12775 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12776 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12777 | http_server_properties->SetQuicAlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12778 | server, NetworkIsolationKey(), alternative_service, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12779 | HttpNetworkSession::Params().quic_params.supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12780 | // Mark the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12781 | http_server_properties->MarkAlternativeServiceBroken(alternative_service, |
| 12782 | NetworkIsolationKey()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12783 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12784 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12786 | request.method = "GET"; |
| 12787 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12788 | request.traffic_annotation = |
| 12789 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12790 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12791 | TestCompletionCallback callback; |
| 12792 | NetErrorDetails details; |
| 12793 | EXPECT_FALSE(details.quic_broken); |
| 12794 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12795 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12796 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12797 | EXPECT_TRUE(details.quic_broken); |
| 12798 | } |
| 12799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12800 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12801 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12802 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12803 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12804 | std::string origin_url = "https://origin.example.org:443"; |
| 12805 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12806 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12807 | |
| 12808 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12809 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12810 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12811 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12812 | |
| 12813 | // HTTP/1.1 data for request. |
| 12814 | MockWrite http_writes[] = { |
| 12815 | MockWrite("GET / HTTP/1.1\r\n" |
| 12816 | "Host: alternative1.example.org\r\n" |
| 12817 | "Connection: keep-alive\r\n\r\n"), |
| 12818 | }; |
| 12819 | |
| 12820 | MockRead http_reads[] = { |
| 12821 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12822 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12823 | "Content-Length: 40\r\n\r\n" |
| 12824 | "first HTTP/1.1 response from alternative1"), |
| 12825 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12826 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12827 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12828 | |
| 12829 | StaticSocketDataProvider data_refused; |
| 12830 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12831 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12834 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12835 | session->http_server_properties(); |
| 12836 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12837 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12838 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12839 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12840 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12841 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12842 | alternative_service_info_vector.push_back( |
| 12843 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12844 | alternative_service1, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12845 | session->params().quic_params.supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12846 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12847 | alternative_service_info_vector.push_back( |
| 12848 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12849 | alternative_service2, expiration, |
Nick Harper | 72ade19 | 2019-07-17 03:30:42 | [diff] [blame] | 12850 | session->params().quic_params.supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12851 | |
| 12852 | http_server_properties->SetAlternativeServices( |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12853 | server, NetworkIsolationKey(), alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12854 | |
| 12855 | // Mark one of the QUIC alternative service as broken. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12856 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1, |
| 12857 | NetworkIsolationKey()); |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12858 | EXPECT_EQ(2u, http_server_properties |
| 12859 | ->GetAlternativeServiceInfos(server, NetworkIsolationKey()) |
| 12860 | .size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12861 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12862 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12863 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12864 | request.method = "GET"; |
| 12865 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12866 | request.traffic_annotation = |
| 12867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12868 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12869 | TestCompletionCallback callback; |
| 12870 | NetErrorDetails details; |
| 12871 | EXPECT_FALSE(details.quic_broken); |
| 12872 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12873 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12874 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12875 | EXPECT_FALSE(details.quic_broken); |
| 12876 | } |
| 12877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12878 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12879 | HttpRequestInfo request; |
| 12880 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12881 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12882 | request.traffic_annotation = |
| 12883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12884 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12885 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12886 | StaticSocketDataProvider first_data; |
| 12887 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12888 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12889 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12890 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12892 | |
| 12893 | MockRead data_reads[] = { |
| 12894 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12895 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12896 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12897 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12898 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12899 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12900 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12902 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12903 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12904 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12905 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12906 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12907 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12908 | // Port is ignored by MockConnect anyway. |
| 12909 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12910 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12911 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12912 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12913 | server, NetworkIsolationKey(), alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12916 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12917 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12920 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12922 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12923 | ASSERT_TRUE(response); |
| 12924 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12925 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12926 | |
| 12927 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12928 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12929 | EXPECT_EQ("hello world", response_data); |
| 12930 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12931 | const AlternativeServiceInfoVector alternative_service_info_vector = |
Matt Menke | 3233d8f2 | 2019-08-20 21:01:49 | [diff] [blame] | 12932 | http_server_properties->GetAlternativeServiceInfos(server, |
| 12933 | NetworkIsolationKey()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12934 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12935 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12936 | alternative_service_info_vector[0].alternative_service()); |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 12937 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 12938 | alternative_service, NetworkIsolationKey())); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12939 | } |
| 12940 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12941 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12942 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12943 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12944 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12945 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12946 | HttpRequestInfo restricted_port_request; |
| 12947 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12948 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12949 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12950 | restricted_port_request.traffic_annotation = |
| 12951 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12952 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12953 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12954 | StaticSocketDataProvider first_data; |
| 12955 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12956 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12957 | |
| 12958 | MockRead data_reads[] = { |
| 12959 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12960 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12961 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12962 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12963 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12964 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12965 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12966 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12968 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12969 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12970 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12971 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12972 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12973 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12974 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12975 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12976 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12977 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 12978 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 12979 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12982 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12983 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 12984 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12985 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12987 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12988 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12989 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12990 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12991 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12992 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12993 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12994 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12995 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12996 | |
| 12997 | HttpRequestInfo restricted_port_request; |
| 12998 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12999 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13000 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13001 | restricted_port_request.traffic_annotation = |
| 13002 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13003 | |
| 13004 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 13005 | StaticSocketDataProvider first_data; |
| 13006 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13007 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13008 | |
| 13009 | MockRead data_reads[] = { |
| 13010 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13011 | MockRead("hello world"), |
| 13012 | MockRead(ASYNC, OK), |
| 13013 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13014 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13015 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13016 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13017 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13021 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13022 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13023 | session->http_server_properties(); |
| 13024 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13025 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13026 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13027 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13028 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13029 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13030 | alternative_service, expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13033 | TestCompletionCallback callback; |
| 13034 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13035 | EXPECT_EQ(ERR_IO_PENDING, |
| 13036 | trans.Start(&restricted_port_request, callback.callback(), |
| 13037 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 13038 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13039 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13040 | } |
| 13041 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13042 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13043 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13044 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13045 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13046 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13047 | HttpRequestInfo restricted_port_request; |
| 13048 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13049 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13050 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13051 | restricted_port_request.traffic_annotation = |
| 13052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13053 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13054 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13055 | StaticSocketDataProvider first_data; |
| 13056 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13057 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13058 | |
| 13059 | MockRead data_reads[] = { |
| 13060 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13061 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13062 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13063 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13064 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13065 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13066 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13067 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13071 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13072 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13073 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13074 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13075 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13076 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13077 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13078 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13079 | url::SchemeHostPort(restricted_port_request.url), NetworkIsolationKey(), |
| 13080 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13082 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13083 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13084 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13085 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 13086 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13088 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13089 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13090 | } |
| 13091 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13092 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13093 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13094 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13095 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13096 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13097 | HttpRequestInfo unrestricted_port_request; |
| 13098 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13099 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13100 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13101 | unrestricted_port_request.traffic_annotation = |
| 13102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13103 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13104 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13105 | StaticSocketDataProvider first_data; |
| 13106 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13107 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13108 | |
| 13109 | MockRead data_reads[] = { |
| 13110 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13111 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13112 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13113 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13114 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13115 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13116 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13117 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13119 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13121 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13122 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13123 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13124 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13125 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13126 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13127 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13128 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13129 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 13130 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13133 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13135 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13136 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13138 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13139 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13140 | } |
| 13141 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13142 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 13143 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 13144 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 13145 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13146 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13147 | HttpRequestInfo unrestricted_port_request; |
| 13148 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13149 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13150 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13151 | unrestricted_port_request.traffic_annotation = |
| 13152 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13153 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13154 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13155 | StaticSocketDataProvider first_data; |
| 13156 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13157 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13158 | |
| 13159 | MockRead data_reads[] = { |
| 13160 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13161 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13162 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13163 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13164 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13165 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13166 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13167 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13169 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13171 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13172 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 13173 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 13174 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13175 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13176 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13177 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13178 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13179 | url::SchemeHostPort(unrestricted_port_request.url), NetworkIsolationKey(), |
| 13180 | alternative_service, expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13183 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13185 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13186 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13188 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13189 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 13190 | } |
| 13191 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13192 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 13193 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 13194 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13195 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13196 | HttpRequestInfo request; |
| 13197 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13198 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13199 | request.traffic_annotation = |
| 13200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13201 | |
| 13202 | // The alternate protocol request will error out before we attempt to connect, |
| 13203 | // so only the standard HTTP request will try to connect. |
| 13204 | MockRead data_reads[] = { |
| 13205 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 13206 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13207 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13208 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13209 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13211 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13212 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13213 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 13214 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13215 | session->http_server_properties(); |
| 13216 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13217 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 13218 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 13219 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13220 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13221 | url::SchemeHostPort(request.url), NetworkIsolationKey(), |
| 13222 | alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13224 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13225 | TestCompletionCallback callback; |
| 13226 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13227 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13229 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13230 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13232 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13233 | ASSERT_TRUE(response); |
| 13234 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13235 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13236 | |
| 13237 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13238 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 13239 | EXPECT_EQ("hello world", response_data); |
| 13240 | } |
| 13241 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13242 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13243 | HttpRequestInfo request; |
| 13244 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13245 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13246 | request.traffic_annotation = |
| 13247 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13248 | |
| 13249 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13250 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13251 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13252 | MockRead("\r\n"), |
| 13253 | MockRead("hello world"), |
| 13254 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13255 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13256 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13257 | StaticSocketDataProvider first_transaction(data_reads, |
| 13258 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13260 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13261 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13263 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13264 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13265 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13266 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13267 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13268 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13269 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13270 | spdy::SpdySerializedFrame resp( |
| 13271 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13272 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13273 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13274 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13275 | }; |
| 13276 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13277 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13279 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13280 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13281 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13282 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13283 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13284 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13285 | &hanging_non_alternate_protocol_socket); |
| 13286 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13287 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13288 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13289 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13290 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13291 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13292 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13293 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13295 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13296 | |
| 13297 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13298 | ASSERT_TRUE(response); |
| 13299 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13300 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13301 | |
| 13302 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13303 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13304 | EXPECT_EQ("hello world", response_data); |
| 13305 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13306 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13307 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13308 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13309 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13310 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13311 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13312 | |
| 13313 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13314 | ASSERT_TRUE(response); |
| 13315 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13316 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13317 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13318 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13319 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13320 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13321 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13322 | } |
| 13323 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13324 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13325 | HttpRequestInfo request; |
| 13326 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13327 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13328 | request.traffic_annotation = |
| 13329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13330 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13331 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13332 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13333 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13334 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13335 | MockRead("\r\n"), |
| 13336 | MockRead("hello world"), |
| 13337 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13338 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13339 | }; |
| 13340 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13341 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13342 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13343 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13344 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13345 | ssl_http11.ssl_info.cert = |
| 13346 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13347 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 13349 | |
| 13350 | // Second transaction starts an alternative and a non-alternative Job. |
| 13351 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13352 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13353 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13354 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13355 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 13356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13357 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13358 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 13359 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13360 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13361 | // Third transaction starts an alternative and a non-alternative job. |
| 13362 | // The non-alternative job hangs, but the alternative one succeeds. |
| 13363 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13364 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13365 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13366 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13367 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13368 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13369 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13370 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13371 | spdy::SpdySerializedFrame resp1( |
| 13372 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13373 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13374 | spdy::SpdySerializedFrame resp2( |
| 13375 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13376 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13377 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13378 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13379 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13380 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13381 | }; |
| 13382 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13383 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13384 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13385 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13386 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13387 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13388 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13389 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13390 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13393 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13394 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13395 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13396 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13398 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13399 | |
| 13400 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13401 | ASSERT_TRUE(response); |
| 13402 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13403 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13404 | |
| 13405 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13406 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13407 | EXPECT_EQ("hello world", response_data); |
| 13408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13409 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13410 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13411 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13414 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13415 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13416 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13418 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13419 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13420 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13421 | |
| 13422 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13423 | ASSERT_TRUE(response); |
| 13424 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13425 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13426 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13427 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13428 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13429 | EXPECT_EQ("hello!", response_data); |
| 13430 | |
| 13431 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13432 | ASSERT_TRUE(response); |
| 13433 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13434 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13435 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13436 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13437 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13438 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13439 | } |
| 13440 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13441 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13442 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13443 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13444 | HttpRequestInfo request; |
| 13445 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13446 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13447 | request.traffic_annotation = |
| 13448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13449 | |
| 13450 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13451 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13452 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13453 | MockRead("\r\n"), |
| 13454 | MockRead("hello world"), |
| 13455 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13456 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13457 | }; |
| 13458 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13459 | StaticSocketDataProvider first_transaction(data_reads, |
| 13460 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13461 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13462 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13463 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13464 | ssl.ssl_info.cert = |
| 13465 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13466 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13468 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13469 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13470 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13471 | hanging_alternate_protocol_socket.set_connect_data( |
| 13472 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13473 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13474 | &hanging_alternate_protocol_socket); |
| 13475 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13476 | // 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] | 13477 | StaticSocketDataProvider second_transaction(data_reads, |
| 13478 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13479 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13482 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13483 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13485 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13486 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13487 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13488 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13490 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13491 | |
| 13492 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13493 | ASSERT_TRUE(response); |
| 13494 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13495 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13496 | |
| 13497 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13498 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13499 | EXPECT_EQ("hello world", response_data); |
| 13500 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13501 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13502 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13503 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13504 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13506 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13507 | |
| 13508 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13509 | ASSERT_TRUE(response); |
| 13510 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13511 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13512 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13513 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13514 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13515 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13516 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13517 | } |
| 13518 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13519 | // Test that proxy is resolved using the origin url, |
| 13520 | // regardless of the alternative server. |
| 13521 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13522 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13523 | ProxyConfig proxy_config; |
| 13524 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13525 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13526 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13527 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13528 | |
| 13529 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13530 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13531 | &capturing_proxy_resolver); |
| 13532 | |
| 13533 | TestNetLog net_log; |
| 13534 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13535 | session_deps_.proxy_resolution_service = |
| 13536 | std::make_unique<ProxyResolutionService>( |
| 13537 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13538 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13539 | |
| 13540 | session_deps_.net_log = &net_log; |
| 13541 | |
| 13542 | // Configure alternative service with a hostname that is not bypassed by the |
| 13543 | // proxy. |
| 13544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13545 | HttpServerProperties* http_server_properties = |
| 13546 | session->http_server_properties(); |
| 13547 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13548 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13549 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13550 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13551 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 13552 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13553 | |
| 13554 | // Non-alternative job should hang. |
| 13555 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13556 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13557 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13558 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13559 | &hanging_alternate_protocol_socket); |
| 13560 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13561 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13562 | |
| 13563 | HttpRequestInfo request; |
| 13564 | request.method = "GET"; |
| 13565 | request.url = GURL("https://www.example.org/"); |
| 13566 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13567 | request.traffic_annotation = |
| 13568 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13569 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13570 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13571 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13572 | |
| 13573 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13574 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13575 | spdy::SpdySerializedFrame resp( |
| 13576 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13577 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13578 | MockRead spdy_reads[] = { |
| 13579 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13580 | }; |
| 13581 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13582 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13583 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13584 | |
| 13585 | TestCompletionCallback callback; |
| 13586 | |
| 13587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13588 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13590 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13591 | |
| 13592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13593 | ASSERT_TRUE(response); |
| 13594 | ASSERT_TRUE(response->headers); |
| 13595 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13596 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13597 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13598 | |
| 13599 | std::string response_data; |
| 13600 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13601 | EXPECT_EQ("hello!", response_data); |
| 13602 | |
| 13603 | // Origin host bypasses proxy, no resolution should have happened. |
| 13604 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13605 | } |
| 13606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13607 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13608 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13609 | proxy_config.set_auto_detect(true); |
| 13610 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13611 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13612 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13613 | session_deps_.proxy_resolution_service = |
| 13614 | std::make_unique<ProxyResolutionService>( |
| 13615 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13616 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13617 | std::make_unique<CapturingProxyResolverFactory>( |
| 13618 | &capturing_proxy_resolver), |
| 13619 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13620 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13621 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13622 | |
| 13623 | HttpRequestInfo request; |
| 13624 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13625 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13626 | request.traffic_annotation = |
| 13627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13628 | |
| 13629 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13630 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13631 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13632 | MockRead("\r\n"), |
| 13633 | MockRead("hello world"), |
| 13634 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13635 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13636 | }; |
| 13637 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13638 | StaticSocketDataProvider first_transaction(data_reads, |
| 13639 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13640 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13641 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13642 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13643 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13644 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13645 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13646 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13647 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13648 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13649 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13650 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13651 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13652 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13654 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13655 | }; |
| 13656 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13657 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13658 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13659 | spdy::SpdySerializedFrame resp( |
| 13660 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13661 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13662 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13663 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13664 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13665 | }; |
| 13666 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13667 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13668 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13669 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13670 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13671 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13672 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13673 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13674 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13675 | &hanging_non_alternate_protocol_socket); |
| 13676 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13677 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13680 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13681 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13682 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13683 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13685 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13686 | |
| 13687 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13688 | ASSERT_TRUE(response); |
| 13689 | ASSERT_TRUE(response->headers); |
| 13690 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13691 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13692 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13693 | |
| 13694 | std::string response_data; |
| 13695 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13696 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13697 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13698 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13699 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13700 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13701 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13703 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13704 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13705 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13706 | ASSERT_TRUE(response); |
| 13707 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13708 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13709 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13710 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13711 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13712 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13713 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13714 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13715 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13716 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13717 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13718 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13719 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13720 | LoadTimingInfo load_timing_info; |
| 13721 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13722 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13723 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13724 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13725 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13726 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13727 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13728 | HttpRequestInfo request; |
| 13729 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13730 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13731 | request.traffic_annotation = |
| 13732 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13733 | |
| 13734 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13735 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13736 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13737 | MockRead("\r\n"), |
| 13738 | MockRead("hello world"), |
| 13739 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13740 | }; |
| 13741 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13742 | StaticSocketDataProvider first_transaction(data_reads, |
| 13743 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13744 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13745 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13746 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13748 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13749 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13750 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13751 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13752 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13753 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13754 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13755 | spdy::SpdySerializedFrame resp( |
| 13756 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13757 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13758 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13759 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13760 | }; |
| 13761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13762 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13763 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13764 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13765 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13768 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13769 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13770 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13771 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13772 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13774 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13775 | |
| 13776 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13777 | ASSERT_TRUE(response); |
| 13778 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13779 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13780 | |
| 13781 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13782 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13783 | EXPECT_EQ("hello world", response_data); |
| 13784 | |
| 13785 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13786 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13787 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13788 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 13789 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 13790 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13791 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13792 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13793 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13794 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13795 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13796 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 13797 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13799 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13800 | |
| 13801 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13802 | ASSERT_TRUE(response); |
| 13803 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13804 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13805 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13806 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13807 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13808 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13809 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13810 | } |
| 13811 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13812 | // GenerateAuthToken is a mighty big test. |
| 13813 | // It tests all permutation of GenerateAuthToken behavior: |
| 13814 | // - Synchronous and Asynchronous completion. |
| 13815 | // - OK or error on completion. |
| 13816 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13817 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13818 | // - Non-authenticating and authenticating backend. |
| 13819 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13820 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13821 | // problems generating an auth token for an authenticating proxy, we don't |
| 13822 | // need to test all permutations of the backend server). |
| 13823 | // |
| 13824 | // The test proceeds by going over each of the configuration cases, and |
| 13825 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13826 | // specifies both the configuration for the test as well as the expectations |
| 13827 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13828 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13829 | static const char kServer[] = "http://www.example.com"; |
| 13830 | static const char kSecureServer[] = "https://www.example.com"; |
| 13831 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13832 | |
| 13833 | enum AuthTiming { |
| 13834 | AUTH_NONE, |
| 13835 | AUTH_SYNC, |
| 13836 | AUTH_ASYNC, |
| 13837 | }; |
| 13838 | |
| 13839 | const MockWrite kGet( |
| 13840 | "GET / HTTP/1.1\r\n" |
| 13841 | "Host: www.example.com\r\n" |
| 13842 | "Connection: keep-alive\r\n\r\n"); |
| 13843 | const MockWrite kGetProxy( |
| 13844 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13845 | "Host: www.example.com\r\n" |
| 13846 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13847 | const MockWrite kGetAuth( |
| 13848 | "GET / HTTP/1.1\r\n" |
| 13849 | "Host: www.example.com\r\n" |
| 13850 | "Connection: keep-alive\r\n" |
| 13851 | "Authorization: auth_token\r\n\r\n"); |
| 13852 | const MockWrite kGetProxyAuth( |
| 13853 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13854 | "Host: www.example.com\r\n" |
| 13855 | "Proxy-Connection: keep-alive\r\n" |
| 13856 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13857 | const MockWrite kGetAuthThroughProxy( |
| 13858 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13859 | "Host: www.example.com\r\n" |
| 13860 | "Proxy-Connection: keep-alive\r\n" |
| 13861 | "Authorization: auth_token\r\n\r\n"); |
| 13862 | const MockWrite kGetAuthWithProxyAuth( |
| 13863 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13864 | "Host: www.example.com\r\n" |
| 13865 | "Proxy-Connection: keep-alive\r\n" |
| 13866 | "Proxy-Authorization: auth_token\r\n" |
| 13867 | "Authorization: auth_token\r\n\r\n"); |
| 13868 | const MockWrite kConnect( |
| 13869 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13870 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13871 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13872 | const MockWrite kConnectProxyAuth( |
| 13873 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13874 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13875 | "Proxy-Connection: keep-alive\r\n" |
| 13876 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13877 | |
| 13878 | const MockRead kSuccess( |
| 13879 | "HTTP/1.1 200 OK\r\n" |
| 13880 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13881 | "Content-Length: 3\r\n\r\n" |
| 13882 | "Yes"); |
| 13883 | const MockRead kFailure( |
| 13884 | "Should not be called."); |
| 13885 | const MockRead kServerChallenge( |
| 13886 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13887 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13888 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13889 | "Content-Length: 14\r\n\r\n" |
| 13890 | "Unauthorized\r\n"); |
| 13891 | const MockRead kProxyChallenge( |
| 13892 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13893 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13894 | "Proxy-Connection: close\r\n" |
| 13895 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13896 | "Content-Length: 14\r\n\r\n" |
| 13897 | "Unauthorized\r\n"); |
| 13898 | const MockRead kProxyConnected( |
| 13899 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13900 | |
| 13901 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13902 | // no constructors, but the C++ compiler on Windows warns about |
| 13903 | // unspecified data in compound literals. So, moved to using constructors, |
| 13904 | // and TestRound's created with the default constructor should not be used. |
| 13905 | struct TestRound { |
| 13906 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13907 | : expected_rv(ERR_UNEXPECTED), |
| 13908 | extra_write(nullptr), |
| 13909 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13910 | TestRound(const MockWrite& write_arg, |
| 13911 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13912 | int expected_rv_arg) |
| 13913 | : write(write_arg), |
| 13914 | read(read_arg), |
| 13915 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13916 | extra_write(nullptr), |
| 13917 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13918 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13919 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13920 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13921 | : write(write_arg), |
| 13922 | read(read_arg), |
| 13923 | expected_rv(expected_rv_arg), |
| 13924 | extra_write(extra_write_arg), |
| 13925 | extra_read(extra_read_arg) { |
| 13926 | } |
| 13927 | MockWrite write; |
| 13928 | MockRead read; |
| 13929 | int expected_rv; |
| 13930 | const MockWrite* extra_write; |
| 13931 | const MockRead* extra_read; |
| 13932 | }; |
| 13933 | |
| 13934 | static const int kNoSSL = 500; |
| 13935 | |
| 13936 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13937 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13938 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13939 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13940 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13941 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13942 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13943 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13944 | int num_auth_rounds; |
| 13945 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13946 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13947 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13948 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13949 | {__LINE__, |
| 13950 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13951 | AUTH_NONE, |
| 13952 | OK, |
| 13953 | kServer, |
| 13954 | AUTH_NONE, |
| 13955 | OK, |
| 13956 | 1, |
| 13957 | kNoSSL, |
| 13958 | {TestRound(kGet, kSuccess, OK)}}, |
| 13959 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13960 | {__LINE__, |
| 13961 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13962 | AUTH_NONE, |
| 13963 | OK, |
| 13964 | kServer, |
| 13965 | AUTH_SYNC, |
| 13966 | OK, |
| 13967 | 2, |
| 13968 | kNoSSL, |
| 13969 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13970 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13971 | {__LINE__, |
| 13972 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13973 | AUTH_NONE, |
| 13974 | OK, |
| 13975 | kServer, |
| 13976 | AUTH_SYNC, |
| 13977 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13978 | 3, |
| 13979 | kNoSSL, |
| 13980 | {TestRound(kGet, kServerChallenge, OK), |
| 13981 | TestRound(kGet, kServerChallenge, OK), |
| 13982 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13983 | {__LINE__, |
| 13984 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13985 | AUTH_NONE, |
| 13986 | OK, |
| 13987 | kServer, |
| 13988 | AUTH_SYNC, |
| 13989 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13990 | 2, |
| 13991 | kNoSSL, |
| 13992 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13993 | {__LINE__, |
| 13994 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13995 | AUTH_NONE, |
| 13996 | OK, |
| 13997 | kServer, |
| 13998 | AUTH_SYNC, |
| 13999 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 14000 | 2, |
| 14001 | kNoSSL, |
| 14002 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14003 | {__LINE__, |
| 14004 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14005 | AUTH_SYNC, |
| 14006 | ERR_FAILED, |
| 14007 | kServer, |
| 14008 | AUTH_NONE, |
| 14009 | OK, |
| 14010 | 2, |
| 14011 | kNoSSL, |
| 14012 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14013 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14014 | {__LINE__, |
| 14015 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14016 | AUTH_ASYNC, |
| 14017 | ERR_FAILED, |
| 14018 | kServer, |
| 14019 | AUTH_NONE, |
| 14020 | OK, |
| 14021 | 2, |
| 14022 | kNoSSL, |
| 14023 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14024 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14025 | {__LINE__, |
| 14026 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14027 | AUTH_NONE, |
| 14028 | OK, |
| 14029 | kServer, |
| 14030 | AUTH_SYNC, |
| 14031 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14032 | 2, |
| 14033 | kNoSSL, |
| 14034 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14035 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14036 | {__LINE__, |
| 14037 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14038 | AUTH_NONE, |
| 14039 | OK, |
| 14040 | kServer, |
| 14041 | AUTH_ASYNC, |
| 14042 | ERR_FAILED, |
| 14043 | 2, |
| 14044 | kNoSSL, |
| 14045 | {TestRound(kGet, kServerChallenge, OK), |
| 14046 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14047 | {__LINE__, |
| 14048 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14049 | AUTH_NONE, |
| 14050 | OK, |
| 14051 | kServer, |
| 14052 | AUTH_ASYNC, |
| 14053 | OK, |
| 14054 | 2, |
| 14055 | kNoSSL, |
| 14056 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14057 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14058 | {__LINE__, |
| 14059 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14060 | AUTH_NONE, |
| 14061 | OK, |
| 14062 | kServer, |
| 14063 | AUTH_ASYNC, |
| 14064 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14065 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14066 | kNoSSL, |
| 14067 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14068 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 14069 | TestRound(kGet, kServerChallenge, OK), |
| 14070 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14071 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14072 | {__LINE__, |
| 14073 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14074 | AUTH_NONE, |
| 14075 | OK, |
| 14076 | kServer, |
| 14077 | AUTH_NONE, |
| 14078 | OK, |
| 14079 | 1, |
| 14080 | kNoSSL, |
| 14081 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 14082 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14083 | {__LINE__, |
| 14084 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14085 | AUTH_NONE, |
| 14086 | OK, |
| 14087 | kServer, |
| 14088 | AUTH_SYNC, |
| 14089 | OK, |
| 14090 | 2, |
| 14091 | kNoSSL, |
| 14092 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14093 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14094 | {__LINE__, |
| 14095 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14096 | AUTH_NONE, |
| 14097 | OK, |
| 14098 | kServer, |
| 14099 | AUTH_SYNC, |
| 14100 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14101 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14102 | kNoSSL, |
| 14103 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14104 | TestRound(kGetProxy, kServerChallenge, OK), |
| 14105 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14106 | {__LINE__, |
| 14107 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14108 | AUTH_NONE, |
| 14109 | OK, |
| 14110 | kServer, |
| 14111 | AUTH_ASYNC, |
| 14112 | OK, |
| 14113 | 2, |
| 14114 | kNoSSL, |
| 14115 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14116 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14117 | {__LINE__, |
| 14118 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14119 | AUTH_NONE, |
| 14120 | OK, |
| 14121 | kServer, |
| 14122 | AUTH_ASYNC, |
| 14123 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14124 | 2, |
| 14125 | kNoSSL, |
| 14126 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14127 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14128 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14129 | {__LINE__, |
| 14130 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14131 | AUTH_SYNC, |
| 14132 | OK, |
| 14133 | kServer, |
| 14134 | AUTH_NONE, |
| 14135 | OK, |
| 14136 | 2, |
| 14137 | kNoSSL, |
| 14138 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14139 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14140 | {__LINE__, |
| 14141 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14142 | AUTH_SYNC, |
| 14143 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14144 | kServer, |
| 14145 | AUTH_NONE, |
| 14146 | OK, |
| 14147 | 2, |
| 14148 | kNoSSL, |
| 14149 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14150 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14151 | {__LINE__, |
| 14152 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14153 | AUTH_ASYNC, |
| 14154 | OK, |
| 14155 | kServer, |
| 14156 | AUTH_NONE, |
| 14157 | OK, |
| 14158 | 2, |
| 14159 | kNoSSL, |
| 14160 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14161 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14162 | {__LINE__, |
| 14163 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14164 | AUTH_ASYNC, |
| 14165 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14166 | kServer, |
| 14167 | AUTH_NONE, |
| 14168 | OK, |
| 14169 | 2, |
| 14170 | kNoSSL, |
| 14171 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14172 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14173 | {__LINE__, |
| 14174 | kProxy, |
| 14175 | AUTH_ASYNC, |
| 14176 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14177 | kServer, |
| 14178 | AUTH_NONE, |
| 14179 | OK, |
| 14180 | 3, |
| 14181 | kNoSSL, |
| 14182 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14183 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14184 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14185 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14186 | {__LINE__, |
| 14187 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14188 | AUTH_SYNC, |
| 14189 | OK, |
| 14190 | kServer, |
| 14191 | AUTH_SYNC, |
| 14192 | OK, |
| 14193 | 3, |
| 14194 | kNoSSL, |
| 14195 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14196 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14197 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14198 | {__LINE__, |
| 14199 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14200 | AUTH_SYNC, |
| 14201 | OK, |
| 14202 | kServer, |
| 14203 | AUTH_SYNC, |
| 14204 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14205 | 3, |
| 14206 | kNoSSL, |
| 14207 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14208 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14209 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14210 | {__LINE__, |
| 14211 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14212 | AUTH_ASYNC, |
| 14213 | OK, |
| 14214 | kServer, |
| 14215 | AUTH_SYNC, |
| 14216 | OK, |
| 14217 | 3, |
| 14218 | kNoSSL, |
| 14219 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14220 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14221 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14222 | {__LINE__, |
| 14223 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14224 | AUTH_ASYNC, |
| 14225 | OK, |
| 14226 | kServer, |
| 14227 | AUTH_SYNC, |
| 14228 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14229 | 3, |
| 14230 | kNoSSL, |
| 14231 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14232 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14233 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14234 | {__LINE__, |
| 14235 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14236 | AUTH_SYNC, |
| 14237 | OK, |
| 14238 | kServer, |
| 14239 | AUTH_ASYNC, |
| 14240 | OK, |
| 14241 | 3, |
| 14242 | kNoSSL, |
| 14243 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14244 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14245 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14246 | {__LINE__, |
| 14247 | kProxy, |
| 14248 | AUTH_SYNC, |
| 14249 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14250 | kServer, |
| 14251 | AUTH_ASYNC, |
| 14252 | OK, |
| 14253 | 4, |
| 14254 | kNoSSL, |
| 14255 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14256 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14257 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14258 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 14259 | {__LINE__, |
| 14260 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14261 | AUTH_SYNC, |
| 14262 | OK, |
| 14263 | kServer, |
| 14264 | AUTH_ASYNC, |
| 14265 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14266 | 3, |
| 14267 | kNoSSL, |
| 14268 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14269 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14270 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14271 | {__LINE__, |
| 14272 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14273 | AUTH_ASYNC, |
| 14274 | OK, |
| 14275 | kServer, |
| 14276 | AUTH_ASYNC, |
| 14277 | OK, |
| 14278 | 3, |
| 14279 | kNoSSL, |
| 14280 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14281 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14282 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 14286 | OK, |
| 14287 | kServer, |
| 14288 | AUTH_ASYNC, |
| 14289 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14290 | 3, |
| 14291 | kNoSSL, |
| 14292 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14293 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14294 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14295 | {__LINE__, |
| 14296 | kProxy, |
| 14297 | AUTH_ASYNC, |
| 14298 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14299 | kServer, |
| 14300 | AUTH_ASYNC, |
| 14301 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14302 | 4, |
| 14303 | kNoSSL, |
| 14304 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 14305 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 14306 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 14307 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14308 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14309 | {__LINE__, |
| 14310 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14311 | AUTH_NONE, |
| 14312 | OK, |
| 14313 | kSecureServer, |
| 14314 | AUTH_NONE, |
| 14315 | OK, |
| 14316 | 1, |
| 14317 | 0, |
| 14318 | {TestRound(kGet, kSuccess, OK)}}, |
| 14319 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14320 | {__LINE__, |
| 14321 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14322 | AUTH_NONE, |
| 14323 | OK, |
| 14324 | kSecureServer, |
| 14325 | AUTH_SYNC, |
| 14326 | OK, |
| 14327 | 2, |
| 14328 | 0, |
| 14329 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14330 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14331 | {__LINE__, |
| 14332 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14333 | AUTH_NONE, |
| 14334 | OK, |
| 14335 | kSecureServer, |
| 14336 | AUTH_SYNC, |
| 14337 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14338 | 2, |
| 14339 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14340 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14341 | {__LINE__, |
| 14342 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14343 | AUTH_NONE, |
| 14344 | OK, |
| 14345 | kSecureServer, |
| 14346 | AUTH_ASYNC, |
| 14347 | OK, |
| 14348 | 2, |
| 14349 | 0, |
| 14350 | {TestRound(kGet, kServerChallenge, OK), |
[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 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14354 | AUTH_NONE, |
| 14355 | OK, |
| 14356 | kSecureServer, |
| 14357 | AUTH_ASYNC, |
| 14358 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14359 | 2, |
| 14360 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14361 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14362 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14363 | {__LINE__, |
| 14364 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14365 | AUTH_NONE, |
| 14366 | OK, |
| 14367 | kSecureServer, |
| 14368 | AUTH_NONE, |
| 14369 | OK, |
| 14370 | 1, |
| 14371 | 0, |
| 14372 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14373 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14374 | {__LINE__, |
| 14375 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14376 | AUTH_NONE, |
| 14377 | OK, |
| 14378 | kSecureServer, |
| 14379 | AUTH_SYNC, |
| 14380 | OK, |
| 14381 | 2, |
| 14382 | 0, |
| 14383 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14384 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14385 | {__LINE__, |
| 14386 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14387 | AUTH_NONE, |
| 14388 | OK, |
| 14389 | kSecureServer, |
| 14390 | AUTH_SYNC, |
| 14391 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14392 | 2, |
| 14393 | 0, |
| 14394 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14395 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14396 | {__LINE__, |
| 14397 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14398 | AUTH_NONE, |
| 14399 | OK, |
| 14400 | kSecureServer, |
| 14401 | AUTH_ASYNC, |
| 14402 | OK, |
| 14403 | 2, |
| 14404 | 0, |
| 14405 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14406 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14407 | {__LINE__, |
| 14408 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14409 | AUTH_NONE, |
| 14410 | OK, |
| 14411 | kSecureServer, |
| 14412 | AUTH_ASYNC, |
| 14413 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14414 | 2, |
| 14415 | 0, |
| 14416 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14417 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14418 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14419 | {__LINE__, |
| 14420 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14421 | AUTH_SYNC, |
| 14422 | OK, |
| 14423 | kSecureServer, |
| 14424 | AUTH_NONE, |
| 14425 | OK, |
| 14426 | 2, |
| 14427 | 1, |
| 14428 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14429 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
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_SYNC, |
| 14433 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14434 | kSecureServer, |
| 14435 | AUTH_NONE, |
| 14436 | OK, |
| 14437 | 2, |
| 14438 | kNoSSL, |
| 14439 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14440 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14441 | {__LINE__, |
| 14442 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14443 | AUTH_SYNC, |
| 14444 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14445 | kSecureServer, |
| 14446 | AUTH_NONE, |
| 14447 | OK, |
| 14448 | 2, |
| 14449 | kNoSSL, |
| 14450 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14451 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14452 | {__LINE__, |
| 14453 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14454 | AUTH_SYNC, |
| 14455 | ERR_UNEXPECTED, |
| 14456 | kSecureServer, |
| 14457 | AUTH_NONE, |
| 14458 | OK, |
| 14459 | 2, |
| 14460 | kNoSSL, |
| 14461 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14462 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14463 | {__LINE__, |
| 14464 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14465 | AUTH_ASYNC, |
| 14466 | OK, |
| 14467 | kSecureServer, |
| 14468 | AUTH_NONE, |
| 14469 | OK, |
| 14470 | 2, |
| 14471 | 1, |
| 14472 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14473 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14474 | {__LINE__, |
| 14475 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14476 | AUTH_ASYNC, |
| 14477 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14478 | kSecureServer, |
| 14479 | AUTH_NONE, |
| 14480 | OK, |
| 14481 | 2, |
| 14482 | kNoSSL, |
| 14483 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14484 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14485 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14486 | {__LINE__, |
| 14487 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14488 | AUTH_SYNC, |
| 14489 | OK, |
| 14490 | kSecureServer, |
| 14491 | AUTH_SYNC, |
| 14492 | OK, |
| 14493 | 3, |
| 14494 | 1, |
| 14495 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14496 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14497 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14498 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14499 | {__LINE__, |
| 14500 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14501 | AUTH_SYNC, |
| 14502 | OK, |
| 14503 | kSecureServer, |
| 14504 | AUTH_SYNC, |
| 14505 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14506 | 3, |
| 14507 | 1, |
| 14508 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14509 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14510 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14511 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14512 | {__LINE__, |
| 14513 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14514 | AUTH_ASYNC, |
| 14515 | OK, |
| 14516 | kSecureServer, |
| 14517 | AUTH_SYNC, |
| 14518 | OK, |
| 14519 | 3, |
| 14520 | 1, |
| 14521 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14522 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14523 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14524 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14525 | {__LINE__, |
| 14526 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14527 | AUTH_ASYNC, |
| 14528 | OK, |
| 14529 | kSecureServer, |
| 14530 | AUTH_SYNC, |
| 14531 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14532 | 3, |
| 14533 | 1, |
| 14534 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14535 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14536 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14537 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14538 | {__LINE__, |
| 14539 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14540 | AUTH_SYNC, |
| 14541 | OK, |
| 14542 | kSecureServer, |
| 14543 | AUTH_ASYNC, |
| 14544 | OK, |
| 14545 | 3, |
| 14546 | 1, |
| 14547 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14548 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14549 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14550 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14551 | {__LINE__, |
| 14552 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14553 | AUTH_SYNC, |
| 14554 | OK, |
| 14555 | kSecureServer, |
| 14556 | AUTH_ASYNC, |
| 14557 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14558 | 3, |
| 14559 | 1, |
| 14560 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14561 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14562 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14563 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14564 | {__LINE__, |
| 14565 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14566 | AUTH_ASYNC, |
| 14567 | OK, |
| 14568 | kSecureServer, |
| 14569 | AUTH_ASYNC, |
| 14570 | OK, |
| 14571 | 3, |
| 14572 | 1, |
| 14573 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14574 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14575 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14576 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14577 | {__LINE__, |
| 14578 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14579 | AUTH_ASYNC, |
| 14580 | OK, |
| 14581 | kSecureServer, |
| 14582 | AUTH_ASYNC, |
| 14583 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14584 | 3, |
| 14585 | 1, |
| 14586 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14587 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14588 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14589 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14590 | {__LINE__, |
| 14591 | kProxy, |
| 14592 | AUTH_ASYNC, |
| 14593 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14594 | kSecureServer, |
| 14595 | AUTH_ASYNC, |
| 14596 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14597 | 4, |
| 14598 | 2, |
| 14599 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14600 | TestRound(kConnect, kProxyChallenge, OK), |
| 14601 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14602 | &kServerChallenge), |
| 14603 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14604 | }; |
| 14605 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14606 | for (const auto& test_config : test_configs) { |
| 14607 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14608 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14609 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14610 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14611 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14612 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14613 | |
| 14614 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14615 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14616 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14617 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14618 | std::string auth_challenge = "Mock realm=proxy"; |
| 14619 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14620 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14621 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14622 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14623 | empty_ssl_info, origin, |
| 14624 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14625 | auth_handler->SetGenerateExpectation( |
| 14626 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14627 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14628 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14629 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14630 | } |
| 14631 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14632 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14633 | std::string auth_challenge = "Mock realm=server"; |
| 14634 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14635 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14636 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14637 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14638 | empty_ssl_info, origin, |
| 14639 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14640 | auth_handler->SetGenerateExpectation( |
| 14641 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14642 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14643 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14644 | |
| 14645 | // The second handler always succeeds. It should only be used where there |
| 14646 | // are multiple auth sessions for server auth in the same network |
| 14647 | // transaction using the same auth scheme. |
| 14648 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14649 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14650 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14651 | empty_ssl_info, origin, |
| 14652 | NetLogWithSource()); |
| 14653 | second_handler->SetGenerateExpectation(true, OK); |
| 14654 | auth_factory->AddMockHandler(second_handler.release(), |
| 14655 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14656 | } |
| 14657 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14658 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14659 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14660 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14661 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14662 | session_deps_.proxy_resolution_service = |
| 14663 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14664 | } |
| 14665 | |
| 14666 | HttpRequestInfo request; |
| 14667 | request.method = "GET"; |
| 14668 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14669 | request.traffic_annotation = |
| 14670 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14673 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14674 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14675 | |
| 14676 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14677 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14678 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14679 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14680 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14681 | |
| 14682 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14683 | mock_reads.back().push_back(read_write_round.read); |
| 14684 | mock_writes.back().push_back(read_write_round.write); |
| 14685 | |
| 14686 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14687 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14688 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14689 | mock_reads.push_back(std::vector<MockRead>()); |
| 14690 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14691 | } |
| 14692 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14693 | if (read_write_round.extra_read) { |
| 14694 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14695 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14696 | if (read_write_round.extra_write) { |
| 14697 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14698 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14699 | |
| 14700 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14701 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14702 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14703 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14704 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14706 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14707 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14708 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14709 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14710 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14711 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14712 | } |
| 14713 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14714 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14715 | // they are as well. |
| 14716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14717 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14718 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14719 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14720 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14721 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14722 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14723 | int rv; |
| 14724 | if (round == 0) { |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14725 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14726 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14727 | rv = trans.RestartWithAuth( |
| 14728 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14729 | } |
| 14730 | if (rv == ERR_IO_PENDING) |
| 14731 | rv = callback.WaitForResult(); |
| 14732 | |
| 14733 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14734 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14735 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14736 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14737 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14738 | continue; |
| 14739 | } |
| 14740 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14741 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14742 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14743 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14744 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14745 | } |
| 14746 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14747 | } |
| 14748 | } |
| 14749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14750 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14751 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14752 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14753 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14754 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14755 | session_deps_.proxy_resolution_service = |
| 14756 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14757 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14758 | |
| 14759 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14760 | auth_handler->set_connection_based(true); |
| 14761 | std::string auth_challenge = "Mock realm=server"; |
| 14762 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14763 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14764 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14765 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14766 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14767 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14768 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14769 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14770 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14771 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14772 | HttpRequestInfo request; |
| 14773 | request.method = "GET"; |
| 14774 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14775 | request.traffic_annotation = |
| 14776 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14777 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14779 | |
| 14780 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14781 | // to validate that the TCP socket is not released to the pool between |
| 14782 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14783 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14784 | CommonConnectJobParams common_connect_job_params( |
| 14785 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14786 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14787 | 50, // Max sockets for pool |
| 14788 | 1, // Max sockets per group |
| 14789 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 14790 | ProxyServer::Direct(), false, // is_for_websockets |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 14791 | &common_connect_job_params); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14792 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14793 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14794 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14795 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14798 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14799 | |
| 14800 | const MockWrite kGet( |
| 14801 | "GET / HTTP/1.1\r\n" |
| 14802 | "Host: www.example.com\r\n" |
| 14803 | "Connection: keep-alive\r\n\r\n"); |
| 14804 | const MockWrite kGetAuth( |
| 14805 | "GET / HTTP/1.1\r\n" |
| 14806 | "Host: www.example.com\r\n" |
| 14807 | "Connection: keep-alive\r\n" |
| 14808 | "Authorization: auth_token\r\n\r\n"); |
| 14809 | |
| 14810 | const MockRead kServerChallenge( |
| 14811 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14812 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14813 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14814 | "Content-Length: 14\r\n\r\n" |
| 14815 | "Unauthorized\r\n"); |
| 14816 | const MockRead kSuccess( |
| 14817 | "HTTP/1.1 200 OK\r\n" |
| 14818 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14819 | "Content-Length: 3\r\n\r\n" |
| 14820 | "Yes"); |
| 14821 | |
| 14822 | MockWrite writes[] = { |
| 14823 | // First round |
| 14824 | kGet, |
| 14825 | // Second round |
| 14826 | kGetAuth, |
| 14827 | // Third round |
| 14828 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14829 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14830 | kGetAuth, |
| 14831 | // Competing request |
| 14832 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14833 | }; |
| 14834 | MockRead reads[] = { |
| 14835 | // First round |
| 14836 | kServerChallenge, |
| 14837 | // Second round |
| 14838 | kServerChallenge, |
| 14839 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14840 | kServerChallenge, |
| 14841 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14842 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14843 | // Competing response |
| 14844 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14845 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14846 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14847 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14848 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14849 | const ClientSocketPool::GroupId kSocketGroup( |
| 14850 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 14851 | PrivacyMode::PRIVACY_MODE_DISABLED, NetworkIsolationKey(), |
| 14852 | false /* disable_secure_dns */); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14853 | |
| 14854 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14855 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14856 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14857 | if (rv == ERR_IO_PENDING) |
| 14858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14859 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14860 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14861 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14862 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14863 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14864 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14865 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14866 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14867 | // In between rounds, another request comes in for the same domain. |
| 14868 | // It should not be able to grab the TCP socket that trans has already |
| 14869 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14870 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14871 | TestCompletionCallback callback_compete; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14872 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14873 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14875 | // callback_compete.WaitForResult at this point would stall forever, |
| 14876 | // since the HttpNetworkTransaction does not release the request back to |
| 14877 | // the pool until after authentication completes. |
| 14878 | |
| 14879 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14880 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14881 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14882 | if (rv == ERR_IO_PENDING) |
| 14883 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14884 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14885 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14886 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14887 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14888 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14889 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14890 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14891 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14892 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14893 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14894 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14895 | if (rv == ERR_IO_PENDING) |
| 14896 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14897 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14898 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14899 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14900 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14901 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14902 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14903 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14904 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14905 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14906 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14907 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14908 | if (rv == ERR_IO_PENDING) |
| 14909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14910 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14911 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14912 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14913 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14914 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14915 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14916 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14917 | // auth handler should transition to a DONE state in concert with the remote |
| 14918 | // server. But that's not something we can test here with a mock handler. |
| 14919 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14920 | auth_handler->state()); |
| 14921 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14922 | // Read the body since the fourth round was successful. This will also |
| 14923 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14924 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14925 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14926 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14927 | if (rv == ERR_IO_PENDING) |
| 14928 | rv = callback.WaitForResult(); |
| 14929 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14930 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14931 | EXPECT_EQ(0, rv); |
| 14932 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14933 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14934 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14935 | |
| 14936 | // The competing request can now finish. Wait for the headers and then |
| 14937 | // read the body. |
| 14938 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14939 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14940 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14941 | if (rv == ERR_IO_PENDING) |
| 14942 | rv = callback.WaitForResult(); |
| 14943 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14944 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14945 | EXPECT_EQ(0, rv); |
| 14946 | |
| 14947 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14948 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14949 | } |
| 14950 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14951 | // This tests the case that a request is issued via http instead of spdy after |
| 14952 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14953 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14954 | HttpRequestInfo request; |
| 14955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14956 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14957 | request.traffic_annotation = |
| 14958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14959 | |
| 14960 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14961 | MockWrite( |
| 14962 | "GET / HTTP/1.1\r\n" |
| 14963 | "Host: www.example.org\r\n" |
| 14964 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14965 | }; |
| 14966 | |
| 14967 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14968 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14969 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14970 | MockRead("\r\n"), |
| 14971 | MockRead("hello world"), |
| 14972 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14973 | }; |
| 14974 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14975 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14976 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14977 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14979 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14980 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14983 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14984 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14987 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 14988 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14989 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14991 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14993 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14994 | ASSERT_TRUE(response); |
| 14995 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14996 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14997 | |
| 14998 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14999 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15000 | EXPECT_EQ("hello world", response_data); |
| 15001 | |
| 15002 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15003 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 15004 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15005 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 15006 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 15007 | // immediate server closing of the socket. |
| 15008 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15009 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15010 | HttpRequestInfo request; |
| 15011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15012 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15013 | request.traffic_annotation = |
| 15014 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15015 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15016 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15017 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15019 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15020 | spdy::SpdySerializedFrame req( |
| 15021 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15022 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15023 | |
| 15024 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15025 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15026 | }; |
| 15027 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15028 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15029 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15031 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15035 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15038 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 15039 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 15040 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15041 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 15042 | // it gets it. This is needed since the auth handler may get destroyed |
| 15043 | // before we get a chance to query it. |
| 15044 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 15045 | public: |
| 15046 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 15047 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15048 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15049 | |
| 15050 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15051 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 15052 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 15053 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15054 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15055 | *url_ = request->url; |
| 15056 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 15057 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15058 | } |
| 15059 | |
| 15060 | private: |
| 15061 | GURL* url_; |
| 15062 | }; |
| 15063 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15064 | // Test that if we cancel the transaction as the connection is completing, that |
| 15065 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15066 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15067 | // Setup everything about the connection to complete synchronously, so that |
| 15068 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 15069 | // for is the callback from the HttpStreamRequest. |
| 15070 | // Then cancel the transaction. |
| 15071 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 15072 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15073 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15074 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 15075 | MockRead(SYNCHRONOUS, "hello world"), |
| 15076 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15077 | }; |
| 15078 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15079 | HttpRequestInfo request; |
| 15080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15081 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15082 | request.traffic_annotation = |
| 15083 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15084 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15086 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15087 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15088 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15089 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15090 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15093 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15094 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15095 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15096 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 15098 | trans.reset(); // Cancel the transaction here. |
| 15099 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15100 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 15101 | } |
| 15102 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15103 | // Test that if a transaction is cancelled after receiving the headers, the |
| 15104 | // stream is drained properly and added back to the socket pool. The main |
| 15105 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 15106 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 15107 | // deleted. |
| 15108 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15109 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15110 | MockRead data_reads[] = { |
| 15111 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 15112 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 15113 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 15114 | MockRead(ASYNC, "1"), |
| 15115 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 15116 | // HttpNetworkTransaction has been deleted. |
| 15117 | MockRead(ASYNC, "2"), |
| 15118 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 15119 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15120 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15122 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15124 | |
| 15125 | { |
| 15126 | HttpRequestInfo request; |
| 15127 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15128 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15129 | request.traffic_annotation = |
| 15130 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15131 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15133 | TestCompletionCallback callback; |
| 15134 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15135 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15137 | callback.WaitForResult(); |
| 15138 | |
| 15139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15140 | ASSERT_TRUE(response); |
| 15141 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15142 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15143 | |
| 15144 | // The transaction and HttpRequestInfo are deleted. |
| 15145 | } |
| 15146 | |
| 15147 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15148 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15149 | |
| 15150 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15151 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 15152 | } |
| 15153 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15154 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15155 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15156 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15157 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15158 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15159 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15160 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15162 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15163 | HttpRequestInfo request; |
| 15164 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15165 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15166 | request.traffic_annotation = |
| 15167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15168 | |
| 15169 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15170 | MockWrite( |
| 15171 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 15172 | "Host: www.example.org\r\n" |
| 15173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15174 | }; |
| 15175 | |
| 15176 | MockRead data_reads1[] = { |
| 15177 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15178 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15179 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15181 | }; |
| 15182 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15183 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15184 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15186 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15189 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15190 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15191 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15192 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15194 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15196 | |
| 15197 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15198 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15200 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15201 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15202 | |
| 15203 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15204 | EXPECT_EQ(200, response->headers->response_code()); |
| 15205 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15206 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15207 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15208 | HostPortPair::FromString("myproxy:70")), |
| 15209 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15210 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15211 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15212 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15213 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15214 | |
| 15215 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15216 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15217 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15218 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15219 | } |
| 15220 | |
| 15221 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15222 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15223 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15224 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15225 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15226 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15227 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15229 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15230 | HttpRequestInfo request; |
| 15231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15232 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15233 | request.traffic_annotation = |
| 15234 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15235 | |
| 15236 | // Since we have proxy, should try to establish tunnel. |
| 15237 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15238 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15239 | "Host: www.example.org:443\r\n" |
| 15240 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15241 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15242 | MockWrite("GET / HTTP/1.1\r\n" |
| 15243 | "Host: www.example.org\r\n" |
| 15244 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15245 | }; |
| 15246 | |
| 15247 | MockRead data_reads1[] = { |
| 15248 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15249 | |
| 15250 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15251 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15252 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15253 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15254 | }; |
| 15255 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15256 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15257 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15258 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15259 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15261 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15263 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15264 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15265 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15266 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 15267 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15269 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15271 | |
| 15272 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15273 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15274 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15275 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15276 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15277 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15278 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15279 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15280 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15281 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15283 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15284 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15285 | |
| 15286 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15287 | EXPECT_EQ(200, response->headers->response_code()); |
| 15288 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15289 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15290 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15291 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15292 | HostPortPair::FromString("myproxy:70")), |
| 15293 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 15294 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 15295 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 15296 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15297 | |
| 15298 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15299 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 15300 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15301 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15302 | } |
| 15303 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15304 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 15305 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15306 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15307 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15308 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15309 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15310 | BoundTestNetLog log; |
| 15311 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15312 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15313 | |
| 15314 | HttpRequestInfo request; |
| 15315 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15316 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15317 | request.traffic_annotation = |
| 15318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15319 | |
| 15320 | // Since we have proxy, should try to establish tunnel. |
| 15321 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15322 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 15323 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15324 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15325 | |
| 15326 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 15327 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15328 | "Connection: keep-alive\r\n\r\n"), |
| 15329 | }; |
| 15330 | |
| 15331 | MockRead data_reads1[] = { |
| 15332 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 15333 | |
| 15334 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15335 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15336 | MockRead("Content-Length: 100\r\n\r\n"), |
| 15337 | MockRead(SYNCHRONOUS, OK), |
| 15338 | }; |
| 15339 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15340 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15342 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15344 | |
| 15345 | TestCompletionCallback callback1; |
| 15346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15347 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15348 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15349 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15350 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15351 | |
| 15352 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15353 | EXPECT_THAT(rv, IsOk()); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15354 | auto entries = log.GetEntries(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15355 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15356 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15357 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15358 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15359 | entries, pos, |
| 15360 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15361 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15363 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15364 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15365 | |
| 15366 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15367 | EXPECT_EQ(200, response->headers->response_code()); |
| 15368 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15369 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15370 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15371 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15372 | HostPortPair::FromString("myproxy:70")), |
| 15373 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15374 | |
| 15375 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15376 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15377 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15378 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15379 | } |
| 15380 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15381 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15382 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15383 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15384 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15385 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15386 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15387 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15389 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15390 | HttpRequestInfo request; |
| 15391 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15392 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15393 | request.traffic_annotation = |
| 15394 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15395 | |
| 15396 | // Since we have proxy, should try to establish tunnel. |
| 15397 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15398 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15399 | "Host: www.example.org:443\r\n" |
| 15400 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15401 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15402 | MockWrite("GET / HTTP/1.1\r\n" |
| 15403 | "Host: www.example.org\r\n" |
| 15404 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15405 | }; |
| 15406 | |
| 15407 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15408 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15409 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15410 | }; |
| 15411 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15412 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15413 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15414 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15417 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15421 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15423 | |
| 15424 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15425 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 15426 | auto entries = log.GetEntries(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15427 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15428 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15429 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15430 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15431 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15432 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15433 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15434 | } |
| 15435 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15436 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15437 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15438 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15439 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15440 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15441 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15442 | spdy::SpdySerializedFrame resp( |
| 15443 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15444 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15445 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15446 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15447 | }; |
| 15448 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15449 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15450 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15451 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15452 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15453 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15457 | |
| 15458 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15459 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15460 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15461 | PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 15462 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 15463 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15464 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15465 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15466 | |
| 15467 | HttpRequestInfo request; |
| 15468 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15469 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15470 | request.traffic_annotation = |
| 15471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15474 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15475 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15476 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15478 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15479 | } |
| 15480 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15481 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15482 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15483 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15484 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15485 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15486 | request_info.url = GURL("https://www.example.com/"); |
| 15487 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15488 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15489 | request_info.traffic_annotation = |
| 15490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15491 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15492 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15493 | MockWrite data_writes[] = { |
| 15494 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15495 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15496 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15499 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15503 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15504 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15505 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15506 | rv = callback.WaitForResult(); |
| 15507 | ASSERT_EQ(error, rv); |
| 15508 | } |
| 15509 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15510 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15511 | // Just check a grab bag of cert errors. |
| 15512 | static const int kErrors[] = { |
| 15513 | ERR_CERT_COMMON_NAME_INVALID, |
| 15514 | ERR_CERT_AUTHORITY_INVALID, |
| 15515 | ERR_CERT_DATE_INVALID, |
| 15516 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15517 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15518 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15519 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15520 | } |
| 15521 | } |
| 15522 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15523 | // Ensure that a client certificate is removed from the SSL client auth |
| 15524 | // cache when: |
| 15525 | // 1) No proxy is involved. |
| 15526 | // 2) TLS False Start is disabled. |
| 15527 | // 3) The initial TLS handshake requests a client certificate. |
| 15528 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15529 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15530 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15531 | request_info.url = GURL("https://www.example.com/"); |
| 15532 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15533 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15534 | request_info.traffic_annotation = |
| 15535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15536 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 15537 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15538 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15539 | |
| 15540 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15541 | // CertificateRequest is received for the first time, the handshake will |
| 15542 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15543 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15544 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15546 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15547 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15548 | |
| 15549 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15550 | // False Start is not being used, the result of the SSL handshake will be |
| 15551 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15552 | // matches the result of a server sending a handshake_failure alert, |
| 15553 | // rather than a Finished message, because it requires a client |
| 15554 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15555 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15556 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15558 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15559 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15560 | |
| 15561 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15562 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15563 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15564 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15565 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15566 | // requiring a client certificate, this fallback handshake should also |
| 15567 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15568 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15569 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15570 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15572 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15573 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15574 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15575 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15576 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15577 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15578 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15579 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15580 | // requiring a client certificate, this fallback handshake should also |
| 15581 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15582 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15583 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15585 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15586 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15590 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15591 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15592 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15593 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15594 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15595 | |
| 15596 | // Complete the SSL handshake, which should abort due to requiring a |
| 15597 | // client certificate. |
| 15598 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15599 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15600 | |
| 15601 | // Indicate that no certificate should be supplied. From the perspective |
| 15602 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15603 | // certificate, so this is the same as supply a |
| 15604 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15605 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15606 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15607 | |
| 15608 | // Ensure the certificate was added to the client auth cache before |
| 15609 | // allowing the connection to continue restarting. |
| 15610 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15611 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15612 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15613 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15614 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15615 | |
| 15616 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15617 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15618 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15619 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15620 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15621 | |
| 15622 | // Ensure that the client certificate is removed from the cache on a |
| 15623 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15624 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15625 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15626 | } |
| 15627 | |
| 15628 | // Ensure that a client certificate is removed from the SSL client auth |
| 15629 | // cache when: |
| 15630 | // 1) No proxy is involved. |
| 15631 | // 2) TLS False Start is enabled. |
| 15632 | // 3) The initial TLS handshake requests a client certificate. |
| 15633 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15634 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15635 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15636 | request_info.url = GURL("https://www.example.com/"); |
| 15637 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15638 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15639 | request_info.traffic_annotation = |
| 15640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15641 | |
David Benjamin | 1c4b6d01 | 2019-07-08 17:12:57 | [diff] [blame] | 15642 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15643 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15644 | |
| 15645 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15646 | // return successfully after reading up to the peer's Certificate message. |
| 15647 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15648 | // enqueue application data to be sent in the same packet as the |
| 15649 | // ChangeCipherSpec and Finished messages. |
| 15650 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15651 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15652 | // Finished messages. If there was an error negotiating with the peer, |
| 15653 | // such as due to the peer requiring a client certificate when none was |
| 15654 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15655 | // called. |
| 15656 | |
| 15657 | // Like the non-False Start case, when a client certificate is requested by |
| 15658 | // the peer, the handshake is aborted during the Connect() call. |
| 15659 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15660 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15661 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15663 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15664 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15665 | |
| 15666 | // When a client certificate is supplied, Connect() will not be aborted |
| 15667 | // when the peer requests the certificate. Instead, the handshake will |
| 15668 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15669 | // the socket. The handshake messages are not processed until Read() is |
| 15670 | // called, which then detects that the handshake was aborted, due to the |
| 15671 | // peer sending a handshake_failure because it requires a client |
| 15672 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15673 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15674 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15676 | MockRead data2_reads[] = { |
| 15677 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15678 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15679 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15680 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15681 | |
| 15682 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15683 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15684 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15685 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15686 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15688 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15689 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15690 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15691 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15692 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15693 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15694 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15696 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15697 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15698 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15699 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15700 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15701 | ssl_data5.cert_request_info = cert_request.get(); |
| 15702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15703 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15704 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15708 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15709 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15710 | TestCompletionCallback callback; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 15711 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15712 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15713 | |
| 15714 | // Complete the SSL handshake, which should abort due to requiring a |
| 15715 | // client certificate. |
| 15716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15717 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15718 | |
| 15719 | // Indicate that no certificate should be supplied. From the perspective |
| 15720 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15721 | // certificate, so this is the same as supply a |
| 15722 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15723 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15724 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15725 | |
| 15726 | // Ensure the certificate was added to the client auth cache before |
| 15727 | // allowing the connection to continue restarting. |
| 15728 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15729 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15730 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15731 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15732 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15733 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15734 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15735 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15736 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15737 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15738 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15739 | |
| 15740 | // Ensure that the client certificate is removed from the cache on a |
| 15741 | // handshake failure. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15742 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15743 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15744 | } |
| 15745 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15746 | // Ensure that a client certificate is removed from the SSL client auth |
| 15747 | // cache when: |
| 15748 | // 1) An HTTPS proxy is involved. |
| 15749 | // 3) The HTTPS proxy requests a client certificate. |
| 15750 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15751 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15752 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15753 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15754 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15755 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15756 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15757 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15758 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15759 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15760 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15761 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 15762 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15763 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15764 | requests[0].url = GURL("https://www.example.com/"); |
| 15765 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15766 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15767 | requests[0].traffic_annotation = |
| 15768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15769 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15770 | // HTTPS requests are tunneled. |
| 15771 | MockWrite https_writes[] = { |
| 15772 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 15773 | "Host: www.example.com:443\r\n" |
| 15774 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15775 | }; |
| 15776 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15777 | requests[1].url = GURL("http://www.example.com/"); |
| 15778 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15779 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15780 | requests[1].traffic_annotation = |
| 15781 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15782 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15783 | // HTTP requests are not. |
| 15784 | MockWrite http_writes[] = { |
| 15785 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 15786 | "Host: www.example.com\r\n" |
| 15787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15788 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15789 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15790 | // When the server rejects the client certificate, it will close the |
| 15791 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 15792 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 15793 | for (bool reject_in_connect : {true, false}) { |
| 15794 | SCOPED_TRACE(reject_in_connect); |
| 15795 | // Client certificate errors are typically signaled with |
| 15796 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 15797 | // protocol error. |
| 15798 | for (Error reject_error : |
| 15799 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 15800 | SCOPED_TRACE(reject_error); |
| 15801 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 15802 | for (const HttpRequestInfo& request : requests) { |
| 15803 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15804 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15805 | session_deps_.socket_factory = |
| 15806 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15807 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15808 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15809 | // [ssl_]data[1-2]. [ssl_]data3 is not needed because we do not retry |
| 15810 | // for proxies. Rather than represending the endpoint |
| 15811 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15812 | // (proxy:70). |
| 15813 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 15814 | ssl_data1.cert_request_info = cert_request.get(); |
| 15815 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15816 | StaticSocketDataProvider data1; |
| 15817 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15818 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15819 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 15820 | base::Optional<StaticSocketDataProvider> data2; |
| 15821 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 15822 | if (reject_in_connect) { |
| 15823 | ssl_data2.emplace(ASYNC, reject_error); |
| 15824 | // There are no reads or writes. |
| 15825 | data2.emplace(); |
| 15826 | } else { |
| 15827 | ssl_data2.emplace(ASYNC, OK); |
| 15828 | // We will get one Write() in before observing the error in Read(). |
| 15829 | if (request.url.SchemeIsCryptographic()) { |
| 15830 | data2.emplace(error_in_read, https_writes); |
| 15831 | } else { |
| 15832 | data2.emplace(error_in_read, http_writes); |
| 15833 | } |
| 15834 | } |
| 15835 | ssl_data2->cert_request_info = cert_request.get(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15836 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15837 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 15838 | &ssl_data2.value()); |
| 15839 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15840 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15841 | std::unique_ptr<HttpNetworkSession> session = |
| 15842 | CreateSession(&session_deps_); |
| 15843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15844 | |
| 15845 | // Begin the SSL handshake with the proxy. |
| 15846 | TestCompletionCallback callback; |
| 15847 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 15848 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15849 | |
| 15850 | // Complete the SSL handshake, which should abort due to requiring a |
| 15851 | // client certificate. |
| 15852 | rv = callback.WaitForResult(); |
| 15853 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15854 | |
| 15855 | // Indicate that no certificate should be supplied. From the |
| 15856 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 15857 | // real certificate, so this is the same as supply a |
| 15858 | // legitimate-but-unacceptable certificate. |
| 15859 | rv = |
| 15860 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 15861 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15862 | |
| 15863 | // Ensure the certificate was added to the client auth cache before |
| 15864 | // allowing the connection to continue restarting. |
| 15865 | scoped_refptr<X509Certificate> client_cert; |
| 15866 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15867 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15868 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15869 | ASSERT_FALSE(client_cert); |
| 15870 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15871 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15872 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15873 | HostPortPair("www.example.com", 443), &client_cert, |
| 15874 | &client_private_key)); |
| 15875 | |
| 15876 | // Restart the handshake. This will consume ssl_data2. The result code |
| 15877 | // is checked against what ssl_data2 should return. |
| 15878 | rv = callback.WaitForResult(); |
| 15879 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 15880 | IsError(reject_error))); |
| 15881 | |
| 15882 | // Now that the new handshake has failed, ensure that the client |
| 15883 | // certificate was removed from the client auth cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15884 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15885 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15886 | ASSERT_FALSE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15887 | HostPortPair("www.example.com", 443), &client_cert, |
| 15888 | &client_private_key)); |
| 15889 | } |
| 15890 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15891 | } |
| 15892 | } |
| 15893 | |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15894 | // Test that HttpNetworkTransaction correctly handles (mocked) certificate |
| 15895 | // requests during a TLS renegotiation. |
| 15896 | TEST_F(HttpNetworkTransactionTest, CertificateRequestInRenego) { |
| 15897 | HttpRequestInfo request_info; |
| 15898 | request_info.url = GURL("https://www.example.com/"); |
| 15899 | request_info.method = "GET"; |
| 15900 | request_info.load_flags = LOAD_NORMAL; |
| 15901 | request_info.traffic_annotation = |
| 15902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 15903 | |
| 15904 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 15905 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
| 15906 | |
| 15907 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 15908 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 15909 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 15910 | ASSERT_TRUE(identity); |
| 15911 | |
| 15912 | // The first connection's handshake succeeds, but we get |
| 15913 | // ERR_SSL_CLIENT_AUTH_CERT_NEEDED instead of an HTTP response. |
| 15914 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 15915 | ssl_data1.cert_request_info = cert_request.get(); |
| 15916 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15917 | MockWrite data1_writes[] = { |
| 15918 | MockWrite("GET / HTTP/1.1\r\n" |
| 15919 | "Host: www.example.com\r\n" |
| 15920 | "Connection: keep-alive\r\n\r\n"), |
| 15921 | }; |
| 15922 | MockRead data1_reads[] = { |
| 15923 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED), |
| 15924 | }; |
| 15925 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 15926 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15927 | |
| 15928 | // After supplying with certificate, we restart the request from the top, |
| 15929 | // which succeeds this time. |
| 15930 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 15931 | ssl_data2.expected_send_client_cert = true; |
| 15932 | ssl_data2.expected_client_cert = identity->certificate(); |
| 15933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 15934 | MockWrite data2_writes[] = { |
| 15935 | MockWrite("GET / HTTP/1.1\r\n" |
| 15936 | "Host: www.example.com\r\n" |
| 15937 | "Connection: keep-alive\r\n\r\n"), |
| 15938 | }; |
| 15939 | MockRead data2_reads[] = { |
| 15940 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15941 | "Content-Length: 0\r\n\r\n"), |
| 15942 | }; |
| 15943 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 15944 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15945 | |
| 15946 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 15947 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15948 | |
| 15949 | TestCompletionCallback callback; |
| 15950 | int rv = callback.GetResult( |
| 15951 | trans.Start(&request_info, callback.callback(), NetLogWithSource())); |
| 15952 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15953 | |
| 15954 | rv = trans.RestartWithCertificate(identity->certificate(), |
| 15955 | identity->ssl_private_key(), |
| 15956 | callback.callback()); |
| 15957 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15958 | |
| 15959 | // Ensure the certificate was added to the client auth cache |
| 15960 | // allowing the connection to continue restarting. |
| 15961 | scoped_refptr<X509Certificate> client_cert; |
| 15962 | scoped_refptr<SSLPrivateKey> client_private_key; |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15963 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15964 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15965 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15966 | |
| 15967 | // Complete the handshake. The request now succeeds. |
| 15968 | rv = callback.WaitForResult(); |
| 15969 | ASSERT_THAT(rv, IsError(OK)); |
| 15970 | EXPECT_EQ(200, trans.GetResponseInfo()->headers->response_code()); |
| 15971 | |
| 15972 | // The client certificate remains in the cache. |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 15973 | ASSERT_TRUE(session->ssl_client_context()->GetClientCertificate( |
David Benjamin | 1a056608 | 2019-04-30 07:36:19 | [diff] [blame] | 15974 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
| 15975 | EXPECT_TRUE(client_cert->EqualsIncludingChain(identity->certificate())); |
| 15976 | } |
| 15977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15978 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15979 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15980 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15982 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15983 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15984 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15985 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15986 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15987 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15988 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15989 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15990 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15991 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15992 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15993 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15994 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15995 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15996 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15997 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15998 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15999 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16000 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16001 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16002 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16003 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16004 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16005 | }; |
| 16006 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16007 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16008 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16009 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16010 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16011 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 16012 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16013 | HttpRequestInfo request1; |
| 16014 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16015 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16016 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16017 | request1.traffic_annotation = |
| 16018 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16019 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16020 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16021 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16023 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16024 | |
| 16025 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16026 | ASSERT_TRUE(response); |
| 16027 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16028 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16029 | |
| 16030 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16031 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16032 | EXPECT_EQ("hello!", response_data); |
| 16033 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16034 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16035 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 16036 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16037 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16038 | |
| 16039 | HttpRequestInfo request2; |
| 16040 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16041 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16042 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16043 | request2.traffic_annotation = |
| 16044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16045 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16046 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16047 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16049 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16050 | |
| 16051 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16052 | ASSERT_TRUE(response); |
| 16053 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16054 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16055 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16056 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16057 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16058 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16059 | } |
| 16060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16061 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16062 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16063 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16065 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16066 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16067 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16068 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16069 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16070 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16071 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16072 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16073 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16074 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16075 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16076 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16077 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16078 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16079 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16080 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16081 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16082 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16083 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16084 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16085 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16086 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16087 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16088 | }; |
| 16089 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16090 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16091 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16092 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16093 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16094 | |
| 16095 | TestCompletionCallback callback; |
| 16096 | HttpRequestInfo request1; |
| 16097 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16098 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16099 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16100 | request1.traffic_annotation = |
| 16101 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16102 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16103 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16104 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16106 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16107 | |
| 16108 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16109 | ASSERT_TRUE(response); |
| 16110 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16111 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16112 | |
| 16113 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16114 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16115 | EXPECT_EQ("hello!", response_data); |
| 16116 | |
| 16117 | HttpRequestInfo request2; |
| 16118 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16119 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16120 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16121 | request2.traffic_annotation = |
| 16122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16123 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16124 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16125 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16127 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16128 | |
| 16129 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16130 | ASSERT_TRUE(response); |
| 16131 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16132 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16133 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16134 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16135 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16136 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16137 | } |
| 16138 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16139 | // Regression test for https://crbug.com/546991. |
| 16140 | // The server might not be able to serve an IP pooled request, and might send a |
| 16141 | // 421 Misdirected Request response status to indicate this. |
| 16142 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 16143 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 16144 | // Two hosts resolve to the same IP address. |
| 16145 | const std::string ip_addr = "1.2.3.4"; |
| 16146 | IPAddress ip; |
| 16147 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16148 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16149 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16150 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16151 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16152 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16153 | |
| 16154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16155 | |
| 16156 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16157 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16158 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16159 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16160 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16161 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16162 | spdy::SpdySerializedFrame rst( |
| 16163 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16164 | MockWrite writes1[] = { |
| 16165 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16166 | CreateMockWrite(rst, 6), |
| 16167 | }; |
| 16168 | |
| 16169 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16170 | spdy::SpdySerializedFrame resp1( |
| 16171 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16172 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16173 | spdy::SpdyHeaderBlock response_headers; |
| 16174 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16175 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16176 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 16177 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16178 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16179 | |
| 16180 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16181 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16182 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16183 | |
| 16184 | AddSSLSocketData(); |
| 16185 | |
| 16186 | // Retry the second request on a second connection. |
| 16187 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16188 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16189 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 16190 | MockWrite writes2[] = { |
| 16191 | CreateMockWrite(req3, 0), |
| 16192 | }; |
| 16193 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16194 | spdy::SpdySerializedFrame resp3( |
| 16195 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16196 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16197 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 16198 | MockRead(ASYNC, 0, 3)}; |
| 16199 | |
| 16200 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16201 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16203 | |
| 16204 | AddSSLSocketData(); |
| 16205 | |
| 16206 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16207 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 16208 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16209 | EXPECT_THAT(rv, IsOk()); |
| 16210 | |
| 16211 | HttpRequestInfo request1; |
| 16212 | request1.method = "GET"; |
| 16213 | request1.url = GURL("https://www.example.org/"); |
| 16214 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16215 | request1.traffic_annotation = |
| 16216 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16217 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16218 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16219 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16220 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 16221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16222 | rv = callback.WaitForResult(); |
| 16223 | EXPECT_THAT(rv, IsOk()); |
| 16224 | |
| 16225 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 16226 | ASSERT_TRUE(response); |
| 16227 | ASSERT_TRUE(response->headers); |
| 16228 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16229 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16230 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16231 | std::string response_data; |
| 16232 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 16233 | EXPECT_EQ("hello!", response_data); |
| 16234 | |
| 16235 | HttpRequestInfo request2; |
| 16236 | request2.method = "GET"; |
| 16237 | request2.url = GURL("https://mail.example.org/"); |
| 16238 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16239 | request2.traffic_annotation = |
| 16240 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16241 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16242 | |
| 16243 | BoundTestNetLog log; |
| 16244 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 16245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16246 | rv = callback.WaitForResult(); |
| 16247 | EXPECT_THAT(rv, IsOk()); |
| 16248 | |
| 16249 | response = trans2.GetResponseInfo(); |
| 16250 | ASSERT_TRUE(response); |
| 16251 | ASSERT_TRUE(response->headers); |
| 16252 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16253 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16254 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16255 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 16256 | EXPECT_EQ("hello!", response_data); |
| 16257 | |
Eric Roman | 79cc755 | 2019-07-19 02:17:54 | [diff] [blame] | 16258 | auto entries = log.GetEntries(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16259 | ExpectLogContainsSomewhere( |
| 16260 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16261 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16262 | } |
| 16263 | |
| 16264 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 16265 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 16266 | // portions of the response. |
| 16267 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 16268 | // Two hosts resolve to the same IP address. |
| 16269 | const std::string ip_addr = "1.2.3.4"; |
| 16270 | IPAddress ip; |
| 16271 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 16272 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16273 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16274 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16275 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 16276 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 16277 | |
| 16278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16279 | |
| 16280 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16281 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16282 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 16283 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16284 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16285 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16286 | spdy::SpdySerializedFrame rst( |
| 16287 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16288 | MockWrite writes1[] = { |
| 16289 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 16290 | CreateMockWrite(rst, 6), |
| 16291 | }; |
| 16292 | |
| 16293 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16294 | spdy::SpdySerializedFrame resp1( |
| 16295 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 16296 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16297 | spdy::SpdyHeaderBlock response_headers; |
| 16298 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 16299 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16300 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 16301 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 16302 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 16303 | |
| 16304 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16305 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16307 | |
| 16308 | AddSSLSocketData(); |
| 16309 | |
| 16310 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 16311 | // Retry again. |
| 16312 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16313 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16314 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 16315 | MockWrite writes2[] = { |
| 16316 | CreateMockWrite(req3, 0), |
| 16317 | }; |
| 16318 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16319 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16320 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16321 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16322 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 16323 | MockRead(ASYNC, 0, 3)}; |
| 16324 | |
| 16325 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16326 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16327 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 16328 | |
| 16329 | AddSSLSocketData(); |
| 16330 | |
| 16331 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16332 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 16333 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16334 | EXPECT_THAT(rv, IsOk()); |
| 16335 | |
| 16336 | HttpRequestInfo request1; |
| 16337 | request1.method = "GET"; |
| 16338 | request1.url = GURL("https://www.example.org/"); |
| 16339 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16340 | request1.traffic_annotation = |
| 16341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16342 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16343 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16344 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16345 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 16346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16347 | rv = callback.WaitForResult(); |
| 16348 | EXPECT_THAT(rv, IsOk()); |
| 16349 | |
| 16350 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 16351 | ASSERT_TRUE(response); |
| 16352 | ASSERT_TRUE(response->headers); |
| 16353 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 16354 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16355 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16356 | std::string response_data; |
| 16357 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 16358 | EXPECT_EQ("hello!", response_data); |
| 16359 | |
| 16360 | HttpRequestInfo request2; |
| 16361 | request2.method = "GET"; |
| 16362 | request2.url = GURL("https://mail.example.org/"); |
| 16363 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16364 | request2.traffic_annotation = |
| 16365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 16366 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16367 | |
| 16368 | BoundTestNetLog log; |
| 16369 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 16370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16371 | rv = callback.WaitForResult(); |
| 16372 | EXPECT_THAT(rv, IsOk()); |
| 16373 | |
| 16374 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 16375 | // caller. |
| 16376 | response = trans2.GetResponseInfo(); |
| 16377 | ASSERT_TRUE(response); |
| 16378 | ASSERT_TRUE(response->headers); |
| 16379 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 16380 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 16381 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 16382 | EXPECT_TRUE(response->ssl_info.cert); |
| 16383 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 16384 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16385 | } |
| 16386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16387 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 16388 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 16389 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 16390 | session_deps_.host_resolver = |
| 16391 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16393 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 16394 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16395 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16396 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16397 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16398 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16399 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16400 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16401 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16402 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16403 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16404 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16405 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16406 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16407 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16408 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16409 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16410 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16411 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16412 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16413 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 16414 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16415 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16416 | }; |
| 16417 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 16418 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 16419 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16420 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16421 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16422 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 16423 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16424 | HttpRequestInfo request1; |
| 16425 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16426 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16427 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16428 | request1.traffic_annotation = |
| 16429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16430 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16431 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16432 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16434 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16435 | |
| 16436 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16437 | ASSERT_TRUE(response); |
| 16438 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16439 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16440 | |
| 16441 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16442 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16443 | EXPECT_EQ("hello!", response_data); |
| 16444 | |
| 16445 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 16446 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 16447 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16448 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16449 | |
| 16450 | HttpRequestInfo request2; |
| 16451 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 16452 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16453 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16454 | request2.traffic_annotation = |
| 16455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16456 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16457 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16458 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16460 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16461 | |
| 16462 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16463 | ASSERT_TRUE(response); |
| 16464 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16465 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16466 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16467 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16468 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16469 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 16470 | } |
| 16471 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16472 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16473 | const std::string https_url = "https://www.example.org:8080/"; |
| 16474 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16475 | |
| 16476 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16477 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16478 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16479 | |
| 16480 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16481 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16482 | }; |
| 16483 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16484 | spdy::SpdySerializedFrame resp1( |
| 16485 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16486 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16487 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16488 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16489 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16490 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16491 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16492 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16493 | |
| 16494 | // HTTP GET for the HTTP URL |
| 16495 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16496 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16497 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16498 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16499 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16500 | }; |
| 16501 | |
| 16502 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16503 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16504 | MockRead(ASYNC, 2, "hello"), |
| 16505 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16506 | }; |
| 16507 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16508 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16509 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16510 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16511 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16512 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16513 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16514 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16517 | |
| 16518 | // Start the first transaction to set up the SpdySession |
| 16519 | HttpRequestInfo request1; |
| 16520 | request1.method = "GET"; |
| 16521 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16522 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16523 | request1.traffic_annotation = |
| 16524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16525 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16526 | TestCompletionCallback callback1; |
| 16527 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16528 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16529 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16530 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16531 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16532 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16533 | |
| 16534 | // Now, start the HTTP request |
| 16535 | HttpRequestInfo request2; |
| 16536 | request2.method = "GET"; |
| 16537 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16538 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16539 | request2.traffic_annotation = |
| 16540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16541 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16542 | TestCompletionCallback callback2; |
| 16543 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16544 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16545 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16546 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16547 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16548 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16549 | } |
| 16550 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16551 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16552 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16553 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16554 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16555 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16556 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16557 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16558 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16559 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16561 | |
| 16562 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16563 | // negotiated. |
| 16564 | StaticSocketDataProvider data; |
| 16565 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16566 | |
| 16567 | // 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] | 16568 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16569 | // mocked. This way the request relies on the alternate Job. |
| 16570 | StaticSocketDataProvider data_refused; |
| 16571 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16572 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16573 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16574 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16576 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16577 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16578 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16579 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16580 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16581 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16582 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16583 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16585 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16586 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16587 | request.traffic_annotation = |
| 16588 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16589 | TestCompletionCallback callback; |
| 16590 | |
| 16591 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16592 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16593 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16594 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16595 | } |
| 16596 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16597 | // 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] | 16598 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16599 | // succeeds, the request should succeed, even if the latter fails because |
| 16600 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16601 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16602 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16603 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16604 | |
| 16605 | // Negotiate HTTP/1.1 with alternative. |
| 16606 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16607 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16609 | |
| 16610 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16611 | // negotiated. |
| 16612 | StaticSocketDataProvider data; |
| 16613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16614 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16615 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16616 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16617 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16619 | |
| 16620 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16621 | MockWrite("GET / HTTP/1.1\r\n" |
| 16622 | "Host: www.example.org\r\n" |
| 16623 | "Connection: keep-alive\r\n\r\n"), |
| 16624 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16625 | "Host: www.example.org\r\n" |
| 16626 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16627 | }; |
| 16628 | |
| 16629 | MockRead http_reads[] = { |
| 16630 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16631 | MockRead("Content-Type: text/html\r\n"), |
| 16632 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16633 | MockRead("foobar"), |
| 16634 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16635 | MockRead("Content-Type: text/html\r\n"), |
| 16636 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16637 | MockRead("another"), |
| 16638 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16639 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16640 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16641 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16642 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16644 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16645 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16646 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16647 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16648 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16649 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16650 | |
| 16651 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16652 | HttpRequestInfo request1; |
| 16653 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16654 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16655 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16656 | request1.traffic_annotation = |
| 16657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16658 | TestCompletionCallback callback1; |
| 16659 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16660 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16661 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16662 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16663 | |
| 16664 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16665 | ASSERT_TRUE(response1); |
| 16666 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16667 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16668 | |
| 16669 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16670 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16671 | EXPECT_EQ("foobar", response_data1); |
| 16672 | |
| 16673 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16674 | // for alternative service. |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 16675 | EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken( |
| 16676 | alternative_service, NetworkIsolationKey())); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16677 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16678 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16679 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16680 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16681 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16682 | HttpRequestInfo request2; |
| 16683 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16684 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16685 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16686 | request2.traffic_annotation = |
| 16687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16688 | TestCompletionCallback callback2; |
| 16689 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16690 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16691 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16692 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16693 | |
| 16694 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16695 | ASSERT_TRUE(response2); |
| 16696 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16697 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16698 | |
| 16699 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16700 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16701 | EXPECT_EQ("another", response_data2); |
| 16702 | } |
| 16703 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16704 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16705 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16706 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16707 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16708 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16709 | HostPortPair alternative("alternative.example.org", 443); |
| 16710 | std::string origin_url = "https://origin.example.org:443"; |
| 16711 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16712 | |
| 16713 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16714 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16715 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16717 | |
| 16718 | // HTTP/1.1 data for |request1| and |request2|. |
| 16719 | MockWrite http_writes[] = { |
| 16720 | MockWrite( |
| 16721 | "GET / HTTP/1.1\r\n" |
| 16722 | "Host: alternative.example.org\r\n" |
| 16723 | "Connection: keep-alive\r\n\r\n"), |
| 16724 | MockWrite( |
| 16725 | "GET / HTTP/1.1\r\n" |
| 16726 | "Host: alternative.example.org\r\n" |
| 16727 | "Connection: keep-alive\r\n\r\n"), |
| 16728 | }; |
| 16729 | |
| 16730 | MockRead http_reads[] = { |
| 16731 | MockRead( |
| 16732 | "HTTP/1.1 200 OK\r\n" |
| 16733 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16734 | "Content-Length: 40\r\n\r\n" |
| 16735 | "first HTTP/1.1 response from alternative"), |
| 16736 | MockRead( |
| 16737 | "HTTP/1.1 200 OK\r\n" |
| 16738 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16739 | "Content-Length: 41\r\n\r\n" |
| 16740 | "second HTTP/1.1 response from alternative"), |
| 16741 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16742 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16743 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16744 | |
| 16745 | // This test documents that an alternate Job should not pool to an already |
| 16746 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16747 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16748 | StaticSocketDataProvider data_refused; |
| 16749 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16750 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16751 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16752 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16754 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16755 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16756 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16757 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16758 | http_server_properties->SetHttp2AlternativeService( |
Matt Menke | 9aa8626 | 2019-08-21 15:52:07 | [diff] [blame] | 16759 | server, NetworkIsolationKey(), alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16760 | |
| 16761 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16762 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16763 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16764 | request1.method = "GET"; |
| 16765 | request1.url = GURL(alternative_url); |
| 16766 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16767 | request1.traffic_annotation = |
| 16768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16769 | TestCompletionCallback callback1; |
| 16770 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16771 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16772 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16773 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16774 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16775 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16776 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16777 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16778 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16779 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16780 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16781 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16782 | |
| 16783 | // Request for origin.example.org, which has an alternative service. This |
| 16784 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16785 | // 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] | 16786 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16787 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16788 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16789 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16790 | request2.method = "GET"; |
| 16791 | request2.url = GURL(origin_url); |
| 16792 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16793 | request2.traffic_annotation = |
| 16794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16795 | TestCompletionCallback callback2; |
| 16796 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16797 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16798 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16799 | |
| 16800 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16801 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16802 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16803 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16804 | request3.method = "GET"; |
| 16805 | request3.url = GURL(alternative_url); |
| 16806 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16807 | request3.traffic_annotation = |
| 16808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16809 | TestCompletionCallback callback3; |
| 16810 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16811 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16812 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16813 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16814 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16815 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16816 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16817 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16818 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16819 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16820 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16821 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16822 | } |
| 16823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16824 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16825 | const std::string https_url = "https://www.example.org:8080/"; |
| 16826 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16827 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16828 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16829 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16830 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16831 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16832 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16833 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16834 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16835 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16836 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16837 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16838 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16839 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16840 | |
| 16841 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16842 | spdy::SpdyHeaderBlock req2_block; |
| 16843 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16844 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16845 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16846 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16847 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16848 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16849 | |
| 16850 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16851 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16852 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16853 | }; |
| 16854 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16855 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16856 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16857 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16858 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16859 | spdy::SpdySerializedFrame body1( |
| 16860 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16861 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16862 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16863 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16864 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16865 | spdy::SpdySerializedFrame resp2( |
| 16866 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16867 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16868 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16869 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16870 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16871 | CreateMockRead(wrapped_resp1, 4), |
| 16872 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16873 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16874 | CreateMockRead(resp2, 8), |
| 16875 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16876 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16877 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16878 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16879 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16880 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16881 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16882 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16883 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16884 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16885 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16886 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16887 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16888 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16889 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16891 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16892 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16894 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16895 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16896 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16897 | |
| 16898 | // Start the first transaction to set up the SpdySession |
| 16899 | HttpRequestInfo request1; |
| 16900 | request1.method = "GET"; |
| 16901 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16902 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16903 | request1.traffic_annotation = |
| 16904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16905 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16906 | TestCompletionCallback callback1; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16907 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16908 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16909 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16910 | data1.RunUntilPaused(); |
| 16911 | base::RunLoop().RunUntilIdle(); |
| 16912 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16913 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16914 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16915 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16916 | LoadTimingInfo load_timing_info1; |
| 16917 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16918 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16919 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16920 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16921 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16922 | HttpRequestInfo request2; |
| 16923 | request2.method = "GET"; |
| 16924 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16925 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16926 | request2.traffic_annotation = |
| 16927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16928 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16929 | TestCompletionCallback callback2; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 16930 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16931 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16932 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16933 | data1.RunUntilPaused(); |
| 16934 | base::RunLoop().RunUntilIdle(); |
| 16935 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16936 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16937 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16938 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16939 | |
| 16940 | LoadTimingInfo load_timing_info2; |
| 16941 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16942 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16943 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16944 | // HTTP requests over a SPDY session should have a different connection |
| 16945 | // socket_log_id than requests over a tunnel. |
| 16946 | 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] | 16947 | } |
| 16948 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16949 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16950 | // that we do not pool other origins that resolve to the same IP when |
| 16951 | // the certificate does not match the new origin. |
| 16952 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16953 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16954 | const std::string url1 = "http://www.example.org/"; |
| 16955 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16956 | const std::string ip_addr = "1.2.3.4"; |
| 16957 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16958 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16959 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16960 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16961 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16962 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16963 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16964 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16965 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16966 | |
| 16967 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16968 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16969 | }; |
| 16970 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16971 | spdy::SpdySerializedFrame resp1( |
| 16972 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16973 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16974 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16975 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16976 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16977 | }; |
| 16978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16979 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16980 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16981 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16982 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16983 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16984 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16985 | |
| 16986 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16987 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16988 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16989 | |
| 16990 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16991 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16992 | }; |
| 16993 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16994 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16995 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16996 | spdy::SpdySerializedFrame body2( |
| 16997 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16998 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16999 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17000 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17001 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17002 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17003 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17004 | |
| 17005 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 17006 | // all others direct. |
| 17007 | ProxyConfig proxy_config; |
| 17008 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17009 | session_deps_.proxy_resolution_service = |
| 17010 | std::make_unique<ProxyResolutionService>( |
| 17011 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17012 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 17013 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17014 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17015 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17016 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17017 | // Load a valid cert. Note, that this does not need to |
| 17018 | // be valid for proxy because the MockSSLClientSocket does |
| 17019 | // not actually verify it. But SpdySession will use this |
| 17020 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17021 | ssl1.ssl_info.cert = |
| 17022 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 17023 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17025 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17026 | |
| 17027 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17028 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17029 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17030 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17031 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17032 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17033 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 17034 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17036 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17037 | |
| 17038 | // Start the first transaction to set up the SpdySession |
| 17039 | HttpRequestInfo request1; |
| 17040 | request1.method = "GET"; |
| 17041 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17042 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17043 | request1.traffic_annotation = |
| 17044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17045 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17046 | TestCompletionCallback callback1; |
| 17047 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17048 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 17049 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 17050 | data1.RunUntilPaused(); |
| 17051 | base::RunLoop().RunUntilIdle(); |
| 17052 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17053 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17054 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17055 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 17056 | |
| 17057 | // Now, start the HTTP request |
| 17058 | HttpRequestInfo request2; |
| 17059 | request2.method = "GET"; |
| 17060 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17061 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17062 | request2.traffic_annotation = |
| 17063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17064 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17065 | TestCompletionCallback callback2; |
| 17066 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17067 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 17068 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17069 | |
| 17070 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17071 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 17072 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17073 | } |
| 17074 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17075 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 17076 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 17077 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 17078 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17079 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17080 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17081 | |
| 17082 | MockRead reads1[] = { |
| 17083 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 17084 | }; |
| 17085 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17086 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17087 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17088 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17089 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17090 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17091 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17092 | }; |
| 17093 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17094 | spdy::SpdySerializedFrame resp2( |
| 17095 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17096 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17097 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17098 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 17099 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17100 | }; |
| 17101 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17102 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17103 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17104 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17105 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17108 | |
| 17109 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17110 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17112 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17113 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17114 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 17115 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17116 | |
| 17117 | // Start the first transaction to set up the SpdySession and verify that |
| 17118 | // connection was closed. |
| 17119 | HttpRequestInfo request1; |
| 17120 | request1.method = "GET"; |
| 17121 | request1.url = GURL(https_url); |
| 17122 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17123 | request1.traffic_annotation = |
| 17124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17125 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17126 | TestCompletionCallback callback1; |
| 17127 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17128 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17129 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17130 | |
| 17131 | // Now, start the second request and make sure it succeeds. |
| 17132 | HttpRequestInfo request2; |
| 17133 | request2.method = "GET"; |
| 17134 | request2.url = GURL(https_url); |
| 17135 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17136 | request2.traffic_annotation = |
| 17137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 17138 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17139 | TestCompletionCallback callback2; |
| 17140 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17141 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17142 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17143 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 17144 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 17145 | } |
| 17146 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17147 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17148 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17149 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17150 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17151 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17152 | |
| 17153 | // Use two different hosts with different IPs so they don't get pooled. |
| 17154 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 17155 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17157 | |
| 17158 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17159 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17160 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17161 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 17163 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 17164 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17165 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17166 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17167 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17168 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17169 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17170 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17171 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17172 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17173 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17174 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17175 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17176 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17177 | }; |
| 17178 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 17179 | // Use a separate test instance for the separate SpdySession that will be |
| 17180 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17181 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17182 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17183 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17184 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17185 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 17186 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17187 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17188 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17189 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17190 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 17191 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17192 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17193 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17194 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17195 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 17196 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17197 | }; |
| 17198 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17199 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 17200 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17201 | |
| 17202 | MockWrite http_write[] = { |
| 17203 | MockWrite("GET / HTTP/1.1\r\n" |
| 17204 | "Host: www.a.com\r\n" |
| 17205 | "Connection: keep-alive\r\n\r\n"), |
| 17206 | }; |
| 17207 | |
| 17208 | MockRead http_read[] = { |
| 17209 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17210 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 17211 | MockRead("Content-Length: 6\r\n\r\n"), |
| 17212 | MockRead("hello!"), |
| 17213 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17214 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17215 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17216 | |
| 17217 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17218 | SpdySessionKey spdy_session_key_a( |
| 17219 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17220 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17221 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17222 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17223 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17224 | |
| 17225 | TestCompletionCallback callback; |
| 17226 | HttpRequestInfo request1; |
| 17227 | request1.method = "GET"; |
| 17228 | request1.url = GURL("https://www.a.com/"); |
| 17229 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17230 | request1.traffic_annotation = |
| 17231 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17232 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17233 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17234 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17235 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17237 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17238 | |
| 17239 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17240 | ASSERT_TRUE(response); |
| 17241 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17242 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17243 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17244 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17245 | |
| 17246 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17247 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17248 | EXPECT_EQ("hello!", response_data); |
| 17249 | trans.reset(); |
| 17250 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17251 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17252 | |
| 17253 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17254 | SpdySessionKey spdy_session_key_b( |
| 17255 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17256 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17257 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17258 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17259 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17260 | HttpRequestInfo request2; |
| 17261 | request2.method = "GET"; |
| 17262 | request2.url = GURL("https://www.b.com/"); |
| 17263 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17264 | request2.traffic_annotation = |
| 17265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17266 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17267 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17268 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17269 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17271 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17272 | |
| 17273 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17274 | ASSERT_TRUE(response); |
| 17275 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 17276 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17277 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17278 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17279 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17280 | EXPECT_EQ("hello!", response_data); |
| 17281 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17282 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17283 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17284 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17285 | |
| 17286 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 17287 | SpdySessionKey spdy_session_key_a1( |
| 17288 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
dalyk | 51ab46b | 2019-10-15 15:14:34 | [diff] [blame] | 17289 | SpdySessionKey::IsProxySession::kFalse, SocketTag(), |
| 17290 | NetworkIsolationKey(), false /* disable_secure_dns */); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17291 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17292 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17293 | HttpRequestInfo request3; |
| 17294 | request3.method = "GET"; |
| 17295 | request3.url = GURL("http://www.a.com/"); |
| 17296 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17297 | request3.traffic_annotation = |
| 17298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17299 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17300 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17301 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17302 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17303 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17304 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17305 | |
| 17306 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17307 | ASSERT_TRUE(response); |
| 17308 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17309 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 17310 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 17311 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17312 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17313 | EXPECT_EQ("hello!", response_data); |
| 17314 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17315 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17316 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 17317 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 17318 | } |
| 17319 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17320 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17321 | HttpRequestInfo request; |
| 17322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17323 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17324 | request.traffic_annotation = |
| 17325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17329 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17330 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17331 | StaticSocketDataProvider data; |
| 17332 | data.set_connect_data(mock_connect); |
| 17333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17334 | |
| 17335 | TestCompletionCallback callback; |
| 17336 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17337 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17339 | |
| 17340 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17341 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17342 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17343 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17344 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17345 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17346 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17347 | |
| 17348 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17349 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17350 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17351 | } |
| 17352 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17353 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17354 | HttpRequestInfo request; |
| 17355 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17356 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17357 | request.traffic_annotation = |
| 17358 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17359 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17362 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17363 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17364 | StaticSocketDataProvider data; |
| 17365 | data.set_connect_data(mock_connect); |
| 17366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17367 | |
| 17368 | TestCompletionCallback callback; |
| 17369 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17370 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17372 | |
| 17373 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17374 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17375 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17376 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17377 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 17378 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17379 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17380 | |
| 17381 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17382 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 17383 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17384 | } |
| 17385 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17386 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17387 | HttpRequestInfo request; |
| 17388 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17389 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17390 | request.traffic_annotation = |
| 17391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17395 | |
| 17396 | MockWrite data_writes[] = { |
| 17397 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17398 | }; |
| 17399 | MockRead data_reads[] = { |
| 17400 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 17401 | }; |
| 17402 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17403 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17405 | |
| 17406 | TestCompletionCallback callback; |
| 17407 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17408 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17410 | |
| 17411 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17412 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17413 | } |
| 17414 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17415 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17416 | HttpRequestInfo request; |
| 17417 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17418 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17419 | request.traffic_annotation = |
| 17420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17421 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17424 | |
| 17425 | MockWrite data_writes[] = { |
| 17426 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 17427 | }; |
| 17428 | MockRead data_reads[] = { |
| 17429 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 17430 | }; |
| 17431 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17432 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17434 | |
| 17435 | TestCompletionCallback callback; |
| 17436 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17439 | |
| 17440 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17441 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17442 | } |
| 17443 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17444 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17445 | HttpRequestInfo request; |
| 17446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17447 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17448 | request.traffic_annotation = |
| 17449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17452 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17453 | |
| 17454 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17455 | MockWrite( |
| 17456 | "GET / HTTP/1.1\r\n" |
| 17457 | "Host: www.example.org\r\n" |
| 17458 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17459 | }; |
| 17460 | MockRead data_reads[] = { |
| 17461 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17462 | }; |
| 17463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17464 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17466 | |
| 17467 | TestCompletionCallback callback; |
| 17468 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17471 | |
| 17472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17473 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17474 | } |
| 17475 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17476 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17477 | HttpRequestInfo request; |
| 17478 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17479 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17480 | request.traffic_annotation = |
| 17481 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17482 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17484 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17485 | |
| 17486 | MockWrite data_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] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17491 | }; |
| 17492 | MockRead data_reads[] = { |
| 17493 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17494 | }; |
| 17495 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17496 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17498 | |
| 17499 | TestCompletionCallback callback; |
| 17500 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17501 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17502 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17503 | |
| 17504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17505 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17506 | } |
| 17507 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17508 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17509 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17510 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17511 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17512 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17513 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17514 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17515 | |
| 17516 | // Set up SSL request. |
| 17517 | |
| 17518 | HttpRequestInfo ssl_request; |
| 17519 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17520 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17521 | ssl_request.traffic_annotation = |
| 17522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17523 | |
| 17524 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17525 | MockWrite( |
| 17526 | "GET / HTTP/1.1\r\n" |
| 17527 | "Host: www.example.org\r\n" |
| 17528 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17529 | }; |
| 17530 | MockRead ssl_reads[] = { |
| 17531 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17532 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17533 | MockRead("hello world"), |
| 17534 | MockRead(SYNCHRONOUS, OK), |
| 17535 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17536 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17537 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17538 | |
| 17539 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17541 | |
| 17542 | // Set up HTTP request. |
| 17543 | |
| 17544 | HttpRequestInfo http_request; |
| 17545 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17546 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17547 | http_request.traffic_annotation = |
| 17548 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17549 | |
| 17550 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17551 | MockWrite( |
| 17552 | "GET / HTTP/1.1\r\n" |
| 17553 | "Host: www.example.org\r\n" |
| 17554 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17555 | }; |
| 17556 | MockRead http_reads[] = { |
| 17557 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17558 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17559 | MockRead("falafel"), |
| 17560 | MockRead(SYNCHRONOUS, OK), |
| 17561 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17562 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17563 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17564 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17565 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17566 | |
| 17567 | // Start the SSL request. |
| 17568 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17569 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17570 | ASSERT_EQ(ERR_IO_PENDING, |
| 17571 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17572 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17573 | |
| 17574 | // Start the HTTP request. Pool should stall. |
| 17575 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17576 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17577 | ASSERT_EQ(ERR_IO_PENDING, |
| 17578 | http_trans.Start(&http_request, http_callback.callback(), |
| 17579 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17580 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17581 | |
| 17582 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17583 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17584 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17585 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17586 | EXPECT_EQ("hello world", response_data); |
| 17587 | |
| 17588 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17589 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17590 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17591 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17592 | |
| 17593 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17594 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17595 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17596 | EXPECT_EQ("falafel", response_data); |
| 17597 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17598 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17599 | } |
| 17600 | |
| 17601 | // Tests that when a SSL connection is established but there's no corresponding |
| 17602 | // request that needs it, the new socket is closed if the transport socket pool |
| 17603 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17604 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17605 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17606 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17607 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17608 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17609 | |
| 17610 | // Set up an ssl request. |
| 17611 | |
| 17612 | HttpRequestInfo ssl_request; |
| 17613 | ssl_request.method = "GET"; |
| 17614 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17615 | ssl_request.traffic_annotation = |
| 17616 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17617 | |
| 17618 | // No data will be sent on the SSL socket. |
| 17619 | StaticSocketDataProvider ssl_data; |
| 17620 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17621 | |
| 17622 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17624 | |
| 17625 | // Set up HTTP request. |
| 17626 | |
| 17627 | HttpRequestInfo http_request; |
| 17628 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17629 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17630 | http_request.traffic_annotation = |
| 17631 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17632 | |
| 17633 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17634 | MockWrite( |
| 17635 | "GET / HTTP/1.1\r\n" |
| 17636 | "Host: www.example.org\r\n" |
| 17637 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17638 | }; |
| 17639 | MockRead http_reads[] = { |
| 17640 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17641 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17642 | MockRead("falafel"), |
| 17643 | MockRead(SYNCHRONOUS, OK), |
| 17644 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17645 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17646 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17649 | |
| 17650 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17651 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17652 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17653 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17654 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17655 | |
| 17656 | // Start the HTTP request. Pool should stall. |
| 17657 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17658 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17659 | ASSERT_EQ(ERR_IO_PENDING, |
| 17660 | http_trans.Start(&http_request, http_callback.callback(), |
| 17661 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17662 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17663 | |
| 17664 | // The SSL connection will automatically be closed once the connection is |
| 17665 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17666 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17667 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17668 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17669 | EXPECT_EQ("falafel", response_data); |
| 17670 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17671 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17672 | } |
| 17673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17674 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17675 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17676 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17677 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17678 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17679 | |
| 17680 | HttpRequestInfo request; |
| 17681 | request.method = "POST"; |
| 17682 | request.url = GURL("http://www.foo.com/"); |
| 17683 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17684 | request.traffic_annotation = |
| 17685 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17689 | // Send headers successfully, but get an error while sending the body. |
| 17690 | MockWrite data_writes[] = { |
| 17691 | MockWrite("POST / HTTP/1.1\r\n" |
| 17692 | "Host: www.foo.com\r\n" |
| 17693 | "Connection: keep-alive\r\n" |
| 17694 | "Content-Length: 3\r\n\r\n"), |
| 17695 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17696 | }; |
| 17697 | |
| 17698 | MockRead data_reads[] = { |
| 17699 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17700 | MockRead("hello world"), |
| 17701 | MockRead(SYNCHRONOUS, OK), |
| 17702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17703 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17705 | |
| 17706 | TestCompletionCallback callback; |
| 17707 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17710 | |
| 17711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17714 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17715 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17716 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17717 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17718 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17719 | |
| 17720 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17721 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17722 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17723 | EXPECT_EQ("hello world", response_data); |
| 17724 | } |
| 17725 | |
| 17726 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17727 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17728 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17729 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17730 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17731 | MockWrite data_writes[] = { |
| 17732 | MockWrite("GET / HTTP/1.1\r\n" |
| 17733 | "Host: www.foo.com\r\n" |
| 17734 | "Connection: keep-alive\r\n\r\n"), |
| 17735 | MockWrite("POST / HTTP/1.1\r\n" |
| 17736 | "Host: www.foo.com\r\n" |
| 17737 | "Connection: keep-alive\r\n" |
| 17738 | "Content-Length: 3\r\n\r\n"), |
| 17739 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17740 | }; |
| 17741 | |
| 17742 | MockRead data_reads[] = { |
| 17743 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17744 | "Content-Length: 14\r\n\r\n"), |
| 17745 | MockRead("first response"), |
| 17746 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17747 | "Content-Length: 15\r\n\r\n"), |
| 17748 | MockRead("second response"), |
| 17749 | MockRead(SYNCHRONOUS, OK), |
| 17750 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17751 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17753 | |
| 17754 | TestCompletionCallback callback; |
| 17755 | HttpRequestInfo request1; |
| 17756 | request1.method = "GET"; |
| 17757 | request1.url = GURL("http://www.foo.com/"); |
| 17758 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17759 | request1.traffic_annotation = |
| 17760 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17761 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17762 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17763 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17764 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17765 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17766 | |
| 17767 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17768 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17769 | |
| 17770 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17771 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17772 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17773 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17774 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17775 | |
| 17776 | std::string response_data1; |
| 17777 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17778 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17779 | EXPECT_EQ("first response", response_data1); |
| 17780 | // Delete the transaction to release the socket back into the socket pool. |
| 17781 | trans1.reset(); |
| 17782 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17783 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17784 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17785 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17786 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17787 | |
| 17788 | HttpRequestInfo request2; |
| 17789 | request2.method = "POST"; |
| 17790 | request2.url = GURL("http://www.foo.com/"); |
| 17791 | request2.upload_data_stream = &upload_data_stream; |
| 17792 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17793 | request2.traffic_annotation = |
| 17794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17796 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17797 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17799 | |
| 17800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17803 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17804 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17805 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17806 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17807 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17808 | |
| 17809 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17810 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17811 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17812 | EXPECT_EQ("second response", response_data2); |
| 17813 | } |
| 17814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17815 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17816 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17817 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17818 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17819 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17820 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17821 | |
| 17822 | HttpRequestInfo request; |
| 17823 | request.method = "POST"; |
| 17824 | request.url = GURL("http://www.foo.com/"); |
| 17825 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17826 | request.traffic_annotation = |
| 17827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17831 | // Send headers successfully, but get an error while sending the body. |
| 17832 | MockWrite data_writes[] = { |
| 17833 | MockWrite("POST / HTTP/1.1\r\n" |
| 17834 | "Host: www.foo.com\r\n" |
| 17835 | "Connection: keep-alive\r\n" |
| 17836 | "Content-Length: 3\r\n\r\n" |
| 17837 | "fo"), |
| 17838 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17839 | }; |
| 17840 | |
| 17841 | MockRead data_reads[] = { |
| 17842 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17843 | MockRead("hello world"), |
| 17844 | MockRead(SYNCHRONOUS, OK), |
| 17845 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17846 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17848 | |
| 17849 | TestCompletionCallback callback; |
| 17850 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17851 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17853 | |
| 17854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17856 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17857 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17858 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17859 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17860 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17861 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17862 | |
| 17863 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17864 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17865 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17866 | EXPECT_EQ("hello world", response_data); |
| 17867 | } |
| 17868 | |
| 17869 | // This tests the more common case than the previous test, where headers and |
| 17870 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17871 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17872 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17873 | |
| 17874 | HttpRequestInfo request; |
| 17875 | request.method = "POST"; |
| 17876 | request.url = GURL("http://www.foo.com/"); |
| 17877 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17878 | request.traffic_annotation = |
| 17879 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17880 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17882 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17883 | // Send headers successfully, but get an error while sending the body. |
| 17884 | MockWrite data_writes[] = { |
| 17885 | MockWrite("POST / HTTP/1.1\r\n" |
| 17886 | "Host: www.foo.com\r\n" |
| 17887 | "Connection: keep-alive\r\n" |
| 17888 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17889 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17890 | }; |
| 17891 | |
| 17892 | MockRead data_reads[] = { |
| 17893 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17894 | MockRead("hello world"), |
| 17895 | MockRead(SYNCHRONOUS, OK), |
| 17896 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17897 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17899 | |
| 17900 | TestCompletionCallback callback; |
| 17901 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17902 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17904 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17905 | // they can't be merged with the body in a single send. Not currently |
| 17906 | // necessary since a chunked body is never merged with headers, but this makes |
| 17907 | // the test more future proof. |
| 17908 | base::RunLoop().RunUntilIdle(); |
| 17909 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17910 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17911 | |
| 17912 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17915 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17916 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17917 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17918 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17919 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17920 | |
| 17921 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17922 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17924 | EXPECT_EQ("hello world", response_data); |
| 17925 | } |
| 17926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17927 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17928 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17929 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17930 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17931 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17932 | |
| 17933 | HttpRequestInfo request; |
| 17934 | request.method = "POST"; |
| 17935 | request.url = GURL("http://www.foo.com/"); |
| 17936 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17937 | request.traffic_annotation = |
| 17938 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17939 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17940 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17942 | |
| 17943 | MockWrite data_writes[] = { |
| 17944 | MockWrite("POST / HTTP/1.1\r\n" |
| 17945 | "Host: www.foo.com\r\n" |
| 17946 | "Connection: keep-alive\r\n" |
| 17947 | "Content-Length: 3\r\n\r\n"), |
| 17948 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17949 | }; |
| 17950 | |
| 17951 | MockRead data_reads[] = { |
| 17952 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17953 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17954 | MockRead("hello world"), |
| 17955 | MockRead(SYNCHRONOUS, OK), |
| 17956 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17957 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17958 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17959 | |
| 17960 | TestCompletionCallback callback; |
| 17961 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 17962 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17964 | |
| 17965 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17968 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17969 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17970 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17971 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17972 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17973 | |
| 17974 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17975 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17977 | EXPECT_EQ("hello world", response_data); |
| 17978 | } |
| 17979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17980 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17981 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17982 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17983 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17984 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17985 | |
| 17986 | HttpRequestInfo request; |
| 17987 | request.method = "POST"; |
| 17988 | request.url = GURL("http://www.foo.com/"); |
| 17989 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17990 | request.traffic_annotation = |
| 17991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17992 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17995 | // Send headers successfully, but get an error while sending the body. |
| 17996 | MockWrite data_writes[] = { |
| 17997 | MockWrite("POST / HTTP/1.1\r\n" |
| 17998 | "Host: www.foo.com\r\n" |
| 17999 | "Connection: keep-alive\r\n" |
| 18000 | "Content-Length: 3\r\n\r\n"), |
| 18001 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18002 | }; |
| 18003 | |
| 18004 | MockRead data_reads[] = { |
| 18005 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 18006 | MockRead("hello world"), |
| 18007 | MockRead(SYNCHRONOUS, OK), |
| 18008 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18009 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18011 | |
| 18012 | TestCompletionCallback callback; |
| 18013 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18014 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18016 | |
| 18017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18018 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18019 | } |
| 18020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18021 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18022 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18023 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18024 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18025 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18026 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18027 | |
| 18028 | HttpRequestInfo request; |
| 18029 | request.method = "POST"; |
| 18030 | request.url = GURL("http://www.foo.com/"); |
| 18031 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18032 | request.traffic_annotation = |
| 18033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18037 | // Send headers successfully, but get an error while sending the body. |
| 18038 | MockWrite data_writes[] = { |
| 18039 | MockWrite("POST / HTTP/1.1\r\n" |
| 18040 | "Host: www.foo.com\r\n" |
| 18041 | "Connection: keep-alive\r\n" |
| 18042 | "Content-Length: 3\r\n\r\n"), |
| 18043 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18044 | }; |
| 18045 | |
| 18046 | MockRead data_reads[] = { |
| 18047 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 18048 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 18049 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 18050 | MockRead("Content-Length: 0\r\n\r\n"), |
| 18051 | MockRead(SYNCHRONOUS, OK), |
| 18052 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18053 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18055 | |
| 18056 | TestCompletionCallback callback; |
| 18057 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18058 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18060 | |
| 18061 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18062 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18063 | } |
| 18064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18065 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18066 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18067 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18068 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18069 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18070 | |
| 18071 | HttpRequestInfo request; |
| 18072 | request.method = "POST"; |
| 18073 | request.url = GURL("http://www.foo.com/"); |
| 18074 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18075 | request.traffic_annotation = |
| 18076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18080 | // Send headers successfully, but get an error while sending the body. |
| 18081 | MockWrite data_writes[] = { |
| 18082 | MockWrite("POST / HTTP/1.1\r\n" |
| 18083 | "Host: www.foo.com\r\n" |
| 18084 | "Connection: keep-alive\r\n" |
| 18085 | "Content-Length: 3\r\n\r\n"), |
| 18086 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18087 | }; |
| 18088 | |
| 18089 | MockRead data_reads[] = { |
| 18090 | MockRead("HTTP 0.9 rocks!"), |
| 18091 | MockRead(SYNCHRONOUS, OK), |
| 18092 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18093 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18094 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18095 | |
| 18096 | TestCompletionCallback callback; |
| 18097 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18098 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18100 | |
| 18101 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18102 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18103 | } |
| 18104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18105 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18106 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18107 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18108 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18109 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18110 | |
| 18111 | HttpRequestInfo request; |
| 18112 | request.method = "POST"; |
| 18113 | request.url = GURL("http://www.foo.com/"); |
| 18114 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18115 | request.traffic_annotation = |
| 18116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18120 | // Send headers successfully, but get an error while sending the body. |
| 18121 | MockWrite data_writes[] = { |
| 18122 | MockWrite("POST / HTTP/1.1\r\n" |
| 18123 | "Host: www.foo.com\r\n" |
| 18124 | "Connection: keep-alive\r\n" |
| 18125 | "Content-Length: 3\r\n\r\n"), |
| 18126 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 18127 | }; |
| 18128 | |
| 18129 | MockRead data_reads[] = { |
| 18130 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 18131 | MockRead(SYNCHRONOUS, OK), |
| 18132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18133 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18135 | |
| 18136 | TestCompletionCallback callback; |
| 18137 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18138 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18140 | |
| 18141 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18142 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 18143 | } |
| 18144 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18145 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18146 | |
| 18147 | namespace { |
| 18148 | |
| 18149 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 18150 | headers->SetHeader("Connection", "Upgrade"); |
| 18151 | headers->SetHeader("Upgrade", "websocket"); |
| 18152 | headers->SetHeader("Origin", "http://www.example.org"); |
| 18153 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18154 | } |
| 18155 | |
| 18156 | } // namespace |
| 18157 | |
| 18158 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18159 | for (bool secure : {true, false}) { |
| 18160 | MockWrite data_writes[] = { |
| 18161 | MockWrite("GET / HTTP/1.1\r\n" |
| 18162 | "Host: www.example.org\r\n" |
| 18163 | "Connection: Upgrade\r\n" |
| 18164 | "Upgrade: websocket\r\n" |
| 18165 | "Origin: http://www.example.org\r\n" |
| 18166 | "Sec-WebSocket-Version: 13\r\n" |
| 18167 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18168 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18169 | "client_max_window_bits\r\n\r\n")}; |
| 18170 | |
| 18171 | MockRead data_reads[] = { |
| 18172 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18173 | "Upgrade: websocket\r\n" |
| 18174 | "Connection: Upgrade\r\n" |
| 18175 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 18176 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18177 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18179 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18180 | if (secure) |
| 18181 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18182 | |
| 18183 | HttpRequestInfo request; |
| 18184 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18185 | request.url = |
| 18186 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18187 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18188 | request.traffic_annotation = |
| 18189 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18190 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18191 | TestWebSocketHandshakeStreamCreateHelper |
| 18192 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18193 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18195 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18196 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18197 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18198 | |
| 18199 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18200 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18202 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 18203 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 18204 | ASSERT_TRUE(stream_request); |
| 18205 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 18206 | stream_request->websocket_handshake_stream_create_helper()); |
| 18207 | |
| 18208 | rv = callback.WaitForResult(); |
| 18209 | EXPECT_THAT(rv, IsOk()); |
| 18210 | |
| 18211 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 18212 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18213 | } |
| 18214 | } |
| 18215 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18216 | // Verify that proxy headers are not sent to the destination server when |
| 18217 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18218 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18219 | HttpRequestInfo request; |
| 18220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18221 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18222 | request.traffic_annotation = |
| 18223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18224 | AddWebSocketHeaders(&request.extra_headers); |
| 18225 | |
| 18226 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18227 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18228 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18229 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18232 | |
| 18233 | // Since a proxy is configured, try to establish a tunnel. |
| 18234 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18235 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18236 | "Host: www.example.org:443\r\n" |
| 18237 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18238 | |
| 18239 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18240 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18241 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18242 | "Host: www.example.org:443\r\n" |
| 18243 | "Proxy-Connection: keep-alive\r\n" |
| 18244 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18245 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 18246 | MockWrite("GET / HTTP/1.1\r\n" |
| 18247 | "Host: www.example.org\r\n" |
| 18248 | "Connection: Upgrade\r\n" |
| 18249 | "Upgrade: websocket\r\n" |
| 18250 | "Origin: http://www.example.org\r\n" |
| 18251 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18252 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18253 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18254 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18255 | |
| 18256 | // The proxy responds to the connect with a 407, using a persistent |
| 18257 | // connection. |
| 18258 | MockRead data_reads[] = { |
| 18259 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18260 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 18261 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 18262 | "Content-Length: 0\r\n" |
| 18263 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18264 | |
| 18265 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18266 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18267 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18268 | "Upgrade: websocket\r\n" |
| 18269 | "Connection: Upgrade\r\n" |
| 18270 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18271 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18272 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18273 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18274 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18276 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18277 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18278 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18279 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18280 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18281 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18282 | &websocket_stream_create_helper); |
| 18283 | |
| 18284 | { |
| 18285 | TestCompletionCallback callback; |
| 18286 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18287 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18289 | |
| 18290 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18291 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18292 | } |
| 18293 | |
| 18294 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18295 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18296 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18297 | EXPECT_EQ(407, response->headers->response_code()); |
| 18298 | |
| 18299 | { |
| 18300 | TestCompletionCallback callback; |
| 18301 | |
| 18302 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 18303 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18305 | |
| 18306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18307 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18308 | } |
| 18309 | |
| 18310 | response = trans->GetResponseInfo(); |
| 18311 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18312 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18313 | |
| 18314 | EXPECT_EQ(101, response->headers->response_code()); |
| 18315 | |
| 18316 | trans.reset(); |
| 18317 | session->CloseAllConnections(); |
| 18318 | } |
| 18319 | |
| 18320 | // Verify that proxy headers are not sent to the destination server when |
| 18321 | // establishing a tunnel for an insecure WebSocket connection. |
| 18322 | // This requires the authentication info to be injected into the auth cache |
| 18323 | // due to crbug.com/395064 |
| 18324 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18325 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18326 | HttpRequestInfo request; |
| 18327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 18328 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18329 | request.traffic_annotation = |
| 18330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18331 | AddWebSocketHeaders(&request.extra_headers); |
| 18332 | |
| 18333 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18334 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18335 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18336 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18339 | |
| 18340 | MockWrite data_writes[] = { |
| 18341 | // Try to establish a tunnel for the WebSocket connection, with |
| 18342 | // credentials. Because WebSockets have a separate set of socket pools, |
| 18343 | // they cannot and will not use the same TCP/IP connection as the |
| 18344 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18345 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 18346 | "Host: www.example.org:80\r\n" |
| 18347 | "Proxy-Connection: keep-alive\r\n" |
| 18348 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18349 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18350 | MockWrite("GET / HTTP/1.1\r\n" |
| 18351 | "Host: www.example.org\r\n" |
| 18352 | "Connection: Upgrade\r\n" |
| 18353 | "Upgrade: websocket\r\n" |
| 18354 | "Origin: http://www.example.org\r\n" |
| 18355 | "Sec-WebSocket-Version: 13\r\n" |
| 18356 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 18357 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 18358 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18359 | |
| 18360 | MockRead data_reads[] = { |
| 18361 | // HTTP CONNECT with credentials. |
| 18362 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18363 | |
| 18364 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18365 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 18366 | "Upgrade: websocket\r\n" |
| 18367 | "Connection: Upgrade\r\n" |
| 18368 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18369 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18370 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18372 | |
| 18373 | session->http_auth_cache()->Add( |
Matt Menke | 96092e6 | 2019-10-18 04:09:33 | [diff] [blame^] | 18374 | GURL("http://myproxy:70/"), HttpAuth::AUTH_PROXY, "MyRealm1", |
| 18375 | HttpAuth::AUTH_SCHEME_BASIC, "Basic realm=MyRealm1", |
| 18376 | AuthCredentials(kFoo, kBar), "/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18377 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 18378 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 18379 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 18380 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18381 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18382 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 18383 | &websocket_stream_create_helper); |
| 18384 | |
| 18385 | TestCompletionCallback callback; |
| 18386 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18387 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18389 | |
| 18390 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18391 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18392 | |
| 18393 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18394 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 18395 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 18396 | |
| 18397 | EXPECT_EQ(101, response->headers->response_code()); |
| 18398 | |
| 18399 | trans.reset(); |
| 18400 | session->CloseAllConnections(); |
| 18401 | } |
| 18402 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 18403 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 18404 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 18405 | for (bool secure : {true, false}) { |
| 18406 | SCOPED_TRACE(secure); |
| 18407 | session_deps_.proxy_resolution_service = |
| 18408 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18409 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18410 | session_deps_.enable_quic = true; |
| 18411 | |
| 18412 | HttpRequestInfo request; |
| 18413 | request.url = |
| 18414 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 18415 | AddWebSocketHeaders(&request.extra_headers); |
| 18416 | request.traffic_annotation = |
| 18417 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18418 | |
| 18419 | TestWebSocketHandshakeStreamCreateHelper |
| 18420 | websocket_handshake_stream_create_helper; |
| 18421 | |
| 18422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18423 | HttpNetworkTransaction trans(LOW, session.get()); |
| 18424 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 18425 | &websocket_handshake_stream_create_helper); |
| 18426 | |
| 18427 | TestCompletionCallback callback; |
| 18428 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18430 | |
| 18431 | rv = callback.WaitForResult(); |
| 18432 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18433 | } |
| 18434 | } |
| 18435 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 18436 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 18437 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18438 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18439 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18440 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18441 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18442 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18443 | |
| 18444 | HttpRequestInfo request; |
| 18445 | request.method = "POST"; |
| 18446 | request.url = GURL("http://www.foo.com/"); |
| 18447 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18448 | request.traffic_annotation = |
| 18449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18452 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18453 | MockWrite data_writes[] = { |
| 18454 | MockWrite("POST / HTTP/1.1\r\n" |
| 18455 | "Host: www.foo.com\r\n" |
| 18456 | "Connection: keep-alive\r\n" |
| 18457 | "Content-Length: 3\r\n\r\n"), |
| 18458 | MockWrite("foo"), |
| 18459 | }; |
| 18460 | |
| 18461 | MockRead data_reads[] = { |
| 18462 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18463 | MockRead(SYNCHRONOUS, OK), |
| 18464 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18465 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18467 | |
| 18468 | TestCompletionCallback callback; |
| 18469 | |
| 18470 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18471 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18472 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18473 | |
| 18474 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18475 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18476 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18477 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18478 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18479 | } |
| 18480 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18481 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18482 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18483 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18484 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18485 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18486 | |
| 18487 | HttpRequestInfo request; |
| 18488 | request.method = "POST"; |
| 18489 | request.url = GURL("http://www.foo.com/"); |
| 18490 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18491 | request.traffic_annotation = |
| 18492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18493 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18496 | MockWrite data_writes[] = { |
| 18497 | MockWrite("POST / HTTP/1.1\r\n" |
| 18498 | "Host: www.foo.com\r\n" |
| 18499 | "Connection: keep-alive\r\n" |
| 18500 | "Content-Length: 3\r\n\r\n"), |
| 18501 | MockWrite("foo"), |
| 18502 | }; |
| 18503 | |
| 18504 | MockRead data_reads[] = { |
| 18505 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18506 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18507 | MockRead(SYNCHRONOUS, OK), |
| 18508 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18509 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18510 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18511 | |
| 18512 | TestCompletionCallback callback; |
| 18513 | |
| 18514 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18515 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18516 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18517 | |
| 18518 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18519 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18520 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18521 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18522 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18523 | } |
| 18524 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18525 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18526 | ChunkedUploadDataStream upload_data_stream(0); |
| 18527 | |
| 18528 | HttpRequestInfo request; |
| 18529 | request.method = "POST"; |
| 18530 | request.url = GURL("http://www.foo.com/"); |
| 18531 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18532 | request.traffic_annotation = |
| 18533 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18534 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18537 | // Send headers successfully, but get an error while sending the body. |
| 18538 | MockWrite data_writes[] = { |
| 18539 | MockWrite("POST / HTTP/1.1\r\n" |
| 18540 | "Host: www.foo.com\r\n" |
| 18541 | "Connection: keep-alive\r\n" |
| 18542 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18543 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18544 | }; |
| 18545 | |
| 18546 | MockRead data_reads[] = { |
| 18547 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18548 | MockRead(SYNCHRONOUS, OK), |
| 18549 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18550 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18552 | |
| 18553 | TestCompletionCallback callback; |
| 18554 | |
| 18555 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 18556 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18557 | |
| 18558 | base::RunLoop().RunUntilIdle(); |
| 18559 | upload_data_stream.AppendData("f", 1, false); |
| 18560 | |
| 18561 | base::RunLoop().RunUntilIdle(); |
| 18562 | upload_data_stream.AppendData("oo", 2, true); |
| 18563 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18564 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18565 | |
| 18566 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18567 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18568 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18569 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18570 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18571 | } |
| 18572 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18573 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18574 | const std::string& accept_encoding, |
| 18575 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18576 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18577 | bool should_match) { |
| 18578 | HttpRequestInfo request; |
| 18579 | request.method = "GET"; |
| 18580 | request.url = GURL("http://www.foo.com/"); |
| 18581 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18582 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18583 | request.traffic_annotation = |
| 18584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18585 | |
| 18586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18588 | // Send headers successfully, but get an error while sending the body. |
| 18589 | MockWrite data_writes[] = { |
| 18590 | MockWrite("GET / HTTP/1.1\r\n" |
| 18591 | "Host: www.foo.com\r\n" |
| 18592 | "Connection: keep-alive\r\n" |
| 18593 | "Accept-Encoding: "), |
| 18594 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18595 | }; |
| 18596 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18597 | std::string response_code = "200 OK"; |
| 18598 | std::string extra; |
| 18599 | if (!location.empty()) { |
| 18600 | response_code = "301 Redirect\r\nLocation: "; |
| 18601 | response_code.append(location); |
| 18602 | } |
| 18603 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18604 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18605 | MockRead("HTTP/1.0 "), |
| 18606 | MockRead(response_code.data()), |
| 18607 | MockRead("\r\nContent-Encoding: "), |
| 18608 | MockRead(content_encoding.data()), |
| 18609 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18610 | MockRead(SYNCHRONOUS, OK), |
| 18611 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18612 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18613 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18614 | |
| 18615 | TestCompletionCallback callback; |
| 18616 | |
| 18617 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18619 | |
| 18620 | rv = callback.WaitForResult(); |
| 18621 | if (should_match) { |
| 18622 | EXPECT_THAT(rv, IsOk()); |
| 18623 | } else { |
| 18624 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18625 | } |
| 18626 | } |
| 18627 | |
| 18628 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18629 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18630 | } |
| 18631 | |
| 18632 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18633 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18634 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18635 | } |
| 18636 | |
| 18637 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18638 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18639 | "", false); |
| 18640 | } |
| 18641 | |
| 18642 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18643 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18644 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18645 | } |
| 18646 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18647 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18648 | ProxyConfig proxy_config; |
| 18649 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18650 | proxy_config.set_pac_mandatory(true); |
| 18651 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18652 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18653 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18654 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18655 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18656 | |
| 18657 | HttpRequestInfo request; |
| 18658 | request.method = "GET"; |
| 18659 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18660 | request.traffic_annotation = |
| 18661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18662 | |
| 18663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18665 | |
| 18666 | TestCompletionCallback callback; |
| 18667 | |
| 18668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18670 | EXPECT_THAT(callback.WaitForResult(), |
| 18671 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18672 | } |
| 18673 | |
| 18674 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18675 | ProxyConfig proxy_config; |
| 18676 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18677 | proxy_config.set_pac_mandatory(true); |
| 18678 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18679 | new MockAsyncProxyResolverFactory(false); |
| 18680 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18681 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18682 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18683 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18684 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18685 | HttpRequestInfo request; |
| 18686 | request.method = "GET"; |
| 18687 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18688 | request.traffic_annotation = |
| 18689 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18690 | |
| 18691 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18692 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18693 | |
| 18694 | TestCompletionCallback callback; |
| 18695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18697 | |
| 18698 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18699 | ERR_FAILED, &resolver); |
| 18700 | EXPECT_THAT(callback.WaitForResult(), |
| 18701 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18702 | } |
| 18703 | |
| 18704 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18705 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18706 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18707 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18708 | session_deps_.enable_quic = false; |
| 18709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18710 | |
| 18711 | HttpRequestInfo request; |
| 18712 | request.method = "GET"; |
| 18713 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18714 | request.traffic_annotation = |
| 18715 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18716 | |
| 18717 | TestCompletionCallback callback; |
| 18718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18721 | |
| 18722 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18723 | } |
| 18724 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18725 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18726 | // Reporting tests |
| 18727 | |
| 18728 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18729 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18730 | protected: |
| 18731 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18732 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18733 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18734 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18735 | test_reporting_context_ = test_reporting_context.get(); |
| 18736 | session_deps_.reporting_service = |
| 18737 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18738 | } |
| 18739 | |
| 18740 | TestReportingContext* reporting_context() const { |
| 18741 | return test_reporting_context_; |
| 18742 | } |
| 18743 | |
| 18744 | void clear_reporting_service() { |
| 18745 | session_deps_.reporting_service.reset(); |
| 18746 | test_reporting_context_ = nullptr; |
| 18747 | } |
| 18748 | |
| 18749 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18750 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18751 | HttpRequestInfo request; |
| 18752 | request.method = "GET"; |
| 18753 | request.url = GURL(url_); |
| 18754 | request.traffic_annotation = |
| 18755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18756 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18757 | MockWrite data_writes[] = { |
| 18758 | MockWrite("GET / HTTP/1.1\r\n" |
| 18759 | "Host: www.example.org\r\n" |
| 18760 | "Connection: keep-alive\r\n\r\n"), |
| 18761 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18762 | MockRead data_reads[] = { |
| 18763 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18764 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18765 | "\"endpoints\": [{\"url\": " |
| 18766 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18767 | MockRead("\r\n"), |
| 18768 | MockRead("hello world"), |
| 18769 | MockRead(SYNCHRONOUS, OK), |
| 18770 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18771 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18772 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18773 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18774 | |
| 18775 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18776 | if (request.url.SchemeIsCryptographic()) { |
| 18777 | ssl.ssl_info.cert = |
| 18778 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18779 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18780 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18782 | } |
| 18783 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18784 | TestCompletionCallback callback; |
| 18785 | auto session = CreateSession(&session_deps_); |
| 18786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18787 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18788 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18789 | } |
| 18790 | |
| 18791 | protected: |
| 18792 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18793 | |
| 18794 | private: |
| 18795 | TestReportingContext* test_reporting_context_; |
| 18796 | }; |
| 18797 | |
| 18798 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18799 | DontProcessReportToHeaderNoService) { |
| 18800 | base::HistogramTester histograms; |
| 18801 | clear_reporting_service(); |
| 18802 | RequestPolicy(); |
| 18803 | histograms.ExpectBucketCount( |
| 18804 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18805 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18806 | } |
| 18807 | |
| 18808 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18809 | base::HistogramTester histograms; |
| 18810 | url_ = "http://www.example.org/"; |
| 18811 | RequestPolicy(); |
| 18812 | histograms.ExpectBucketCount( |
| 18813 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18814 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18815 | } |
| 18816 | |
| 18817 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18818 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18819 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
Lily Chen | fc92ff4 | 2019-05-06 22:59:10 | [diff] [blame] | 18820 | const ReportingEndpoint endpoint = |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18821 | reporting_context()->cache()->GetEndpointForTesting( |
| 18822 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18823 | GURL("https://www.example.org/upload/")); |
| 18824 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18825 | } |
| 18826 | |
| 18827 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18828 | DontProcessReportToHeaderInvalidHttps) { |
| 18829 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18830 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18831 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18832 | histograms.ExpectBucketCount( |
| 18833 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18834 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18835 | } |
| 18836 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18837 | |
| 18838 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18839 | // Network Error Logging tests |
| 18840 | |
| 18841 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18842 | namespace { |
| 18843 | |
| 18844 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18845 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18846 | |
| 18847 | } // namespace |
| 18848 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18849 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18850 | : public HttpNetworkTransactionTest { |
| 18851 | protected: |
| 18852 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18853 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18854 | auto network_error_logging_service = |
| 18855 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18856 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18857 | session_deps_.network_error_logging_service = |
| 18858 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18859 | |
| 18860 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18861 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18862 | |
| 18863 | request_.method = "GET"; |
| 18864 | request_.url = GURL(url_); |
| 18865 | request_.extra_headers = extra_headers_; |
| 18866 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18867 | request_.traffic_annotation = |
| 18868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18869 | } |
| 18870 | |
| 18871 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18872 | return test_network_error_logging_service_; |
| 18873 | } |
| 18874 | |
| 18875 | void clear_network_error_logging_service() { |
| 18876 | session_deps_.network_error_logging_service.reset(); |
| 18877 | test_network_error_logging_service_ = nullptr; |
| 18878 | } |
| 18879 | |
| 18880 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18881 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18882 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18883 | MockWrite data_writes[] = { |
| 18884 | MockWrite("GET / HTTP/1.1\r\n" |
| 18885 | "Host: www.example.org\r\n" |
| 18886 | "Connection: keep-alive\r\n"), |
| 18887 | MockWrite(ASYNC, extra_header_string.data(), |
| 18888 | extra_header_string.size()), |
| 18889 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18890 | MockRead data_reads[] = { |
| 18891 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18892 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18893 | MockRead("\r\n"), |
| 18894 | MockRead("hello world"), |
| 18895 | MockRead(SYNCHRONOUS, OK), |
| 18896 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18897 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18898 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18899 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18900 | |
| 18901 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18902 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18903 | ssl.ssl_info.cert = |
| 18904 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18905 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18906 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18908 | } |
| 18909 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18910 | TestCompletionCallback callback; |
| 18911 | auto session = CreateSession(&session_deps_); |
| 18912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18913 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18914 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18915 | |
| 18916 | std::string response_data; |
| 18917 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18918 | EXPECT_EQ("hello world", response_data); |
| 18919 | } |
| 18920 | |
| 18921 | void CheckReport(size_t index, |
| 18922 | int status_code, |
| 18923 | int error_type, |
| 18924 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18925 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18926 | |
| 18927 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18928 | network_error_logging_service()->errors()[index]; |
| 18929 | EXPECT_EQ(url_, error.uri); |
| 18930 | EXPECT_EQ(kReferrer, error.referrer); |
| 18931 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18932 | EXPECT_EQ(server_ip, error.server_ip); |
| 18933 | EXPECT_EQ("http/1.1", error.protocol); |
| 18934 | EXPECT_EQ("GET", error.method); |
| 18935 | EXPECT_EQ(status_code, error.status_code); |
| 18936 | EXPECT_EQ(error_type, error.type); |
| 18937 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18938 | } |
| 18939 | |
| 18940 | protected: |
| 18941 | std::string url_ = "https://www.example.org/"; |
| 18942 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18943 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18944 | HttpRequestHeaders extra_headers_; |
| 18945 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18946 | |
| 18947 | private: |
| 18948 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18949 | }; |
| 18950 | |
| 18951 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18952 | DontProcessNelHeaderNoService) { |
| 18953 | base::HistogramTester histograms; |
| 18954 | clear_network_error_logging_service(); |
| 18955 | RequestPolicy(); |
| 18956 | histograms.ExpectBucketCount( |
| 18957 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18958 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18959 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18960 | 1); |
| 18961 | } |
| 18962 | |
| 18963 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18964 | DontProcessNelHeaderHttp) { |
| 18965 | base::HistogramTester histograms; |
| 18966 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18967 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18968 | RequestPolicy(); |
| 18969 | histograms.ExpectBucketCount( |
| 18970 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18971 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18972 | } |
| 18973 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18974 | // Don't set NEL policies received on a proxied connection. |
| 18975 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18976 | DontProcessNelHeaderProxy) { |
| 18977 | session_deps_.proxy_resolution_service = |
| 18978 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18979 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18980 | BoundTestNetLog log; |
| 18981 | session_deps_.net_log = log.bound().net_log(); |
| 18982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18983 | |
| 18984 | HttpRequestInfo request; |
| 18985 | request.method = "GET"; |
| 18986 | request.url = GURL("https://www.example.org/"); |
| 18987 | request.traffic_annotation = |
| 18988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18989 | |
| 18990 | // Since we have proxy, should try to establish tunnel. |
| 18991 | MockWrite data_writes1[] = { |
| 18992 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18993 | "Host: www.example.org:443\r\n" |
| 18994 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18995 | |
| 18996 | MockWrite("GET / HTTP/1.1\r\n" |
| 18997 | "Host: www.example.org\r\n" |
| 18998 | "Connection: keep-alive\r\n\r\n"), |
| 18999 | }; |
| 19000 | |
| 19001 | MockRead data_reads1[] = { |
| 19002 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19003 | |
| 19004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19005 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 19006 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19007 | MockRead("Content-Length: 100\r\n\r\n"), |
| 19008 | MockRead(SYNCHRONOUS, OK), |
| 19009 | }; |
| 19010 | |
| 19011 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19012 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19013 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19014 | ssl.ssl_info.cert = |
| 19015 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 19016 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 19017 | ssl.ssl_info.cert_status = 0; |
| 19018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19019 | |
| 19020 | TestCompletionCallback callback1; |
| 19021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19022 | |
| 19023 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 19024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19025 | |
| 19026 | rv = callback1.WaitForResult(); |
| 19027 | EXPECT_THAT(rv, IsOk()); |
| 19028 | |
| 19029 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 19030 | ASSERT_TRUE(response); |
| 19031 | EXPECT_EQ(200, response->headers->response_code()); |
| 19032 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 19033 | |
| 19034 | // No NEL header was set. |
| 19035 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 19036 | } |
| 19037 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19038 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 19039 | RequestPolicy(); |
| 19040 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19041 | const auto& header = network_error_logging_service()->headers()[0]; |
| 19042 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 19043 | header.origin); |
| 19044 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 19045 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 19046 | } |
| 19047 | |
| 19048 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19049 | DontProcessNelHeaderInvalidHttps) { |
| 19050 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19051 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 19052 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19053 | histograms.ExpectBucketCount( |
| 19054 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 19055 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 19056 | 1); |
| 19057 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19058 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19059 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19060 | RequestPolicy(); |
| 19061 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19062 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19063 | } |
| 19064 | |
| 19065 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19066 | CreateReportErrorAfterStart) { |
| 19067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19068 | auto trans = |
| 19069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19070 | |
| 19071 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 19072 | StaticSocketDataProvider data; |
| 19073 | data.set_connect_data(mock_connect); |
| 19074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19075 | |
| 19076 | TestCompletionCallback callback; |
| 19077 | |
| 19078 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19079 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 19080 | |
| 19081 | trans.reset(); |
| 19082 | |
| 19083 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19084 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 19085 | IPAddress() /* server_ip */); |
| 19086 | } |
| 19087 | |
| 19088 | // Same as above except the error is ASYNC |
| 19089 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19090 | CreateReportErrorAfterStartAsync) { |
| 19091 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19092 | auto trans = |
| 19093 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19094 | |
| 19095 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 19096 | StaticSocketDataProvider data; |
| 19097 | data.set_connect_data(mock_connect); |
| 19098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19099 | |
| 19100 | TestCompletionCallback callback; |
| 19101 | |
| 19102 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19103 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 19104 | |
| 19105 | trans.reset(); |
| 19106 | |
| 19107 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19108 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 19109 | IPAddress() /* server_ip */); |
| 19110 | } |
| 19111 | |
| 19112 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19113 | CreateReportReadBodyError) { |
| 19114 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19115 | MockWrite data_writes[] = { |
| 19116 | MockWrite("GET / HTTP/1.1\r\n" |
| 19117 | "Host: www.example.org\r\n" |
| 19118 | "Connection: keep-alive\r\n"), |
| 19119 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19120 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19121 | MockRead data_reads[] = { |
| 19122 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19123 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 19124 | MockRead("hello world"), |
| 19125 | MockRead(SYNCHRONOUS, OK), |
| 19126 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19127 | |
| 19128 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19129 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19130 | |
| 19131 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19132 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19133 | |
| 19134 | // Log start time |
| 19135 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19136 | |
| 19137 | TestCompletionCallback callback; |
| 19138 | auto session = CreateSession(&session_deps_); |
| 19139 | auto trans = |
| 19140 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19141 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19142 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19143 | |
| 19144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19145 | ASSERT_TRUE(response); |
| 19146 | |
| 19147 | EXPECT_TRUE(response->headers); |
| 19148 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19149 | |
| 19150 | std::string response_data; |
| 19151 | rv = ReadTransaction(trans.get(), &response_data); |
| 19152 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19153 | |
| 19154 | trans.reset(); |
| 19155 | |
| 19156 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19157 | |
| 19158 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19159 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19160 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19161 | network_error_logging_service()->errors()[0]; |
| 19162 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19163 | } |
| 19164 | |
| 19165 | // Same as above except the final read is ASYNC. |
| 19166 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19167 | CreateReportReadBodyErrorAsync) { |
| 19168 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 19169 | MockWrite data_writes[] = { |
| 19170 | MockWrite("GET / HTTP/1.1\r\n" |
| 19171 | "Host: www.example.org\r\n" |
| 19172 | "Connection: keep-alive\r\n"), |
| 19173 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19174 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19175 | MockRead data_reads[] = { |
| 19176 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19177 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 19178 | MockRead("hello world"), |
| 19179 | MockRead(ASYNC, OK), |
| 19180 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19181 | |
| 19182 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19183 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19184 | |
| 19185 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19187 | |
| 19188 | // Log start time |
| 19189 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19190 | |
| 19191 | TestCompletionCallback callback; |
| 19192 | auto session = CreateSession(&session_deps_); |
| 19193 | auto trans = |
| 19194 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19195 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19196 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19197 | |
| 19198 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19199 | ASSERT_TRUE(response); |
| 19200 | |
| 19201 | EXPECT_TRUE(response->headers); |
| 19202 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19203 | |
| 19204 | std::string response_data; |
| 19205 | rv = ReadTransaction(trans.get(), &response_data); |
| 19206 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 19207 | |
| 19208 | trans.reset(); |
| 19209 | |
| 19210 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19211 | |
| 19212 | CheckReport(0 /* index */, 200 /* status_code */, |
| 19213 | ERR_CONTENT_LENGTH_MISMATCH); |
| 19214 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19215 | network_error_logging_service()->errors()[0]; |
| 19216 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 19217 | } |
| 19218 | |
| 19219 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19220 | CreateReportRestartWithAuth) { |
| 19221 | std::string extra_header_string = extra_headers_.ToString(); |
| 19222 | static const base::TimeDelta kSleepDuration = |
| 19223 | base::TimeDelta::FromMilliseconds(10); |
| 19224 | |
| 19225 | MockWrite data_writes1[] = { |
| 19226 | MockWrite("GET / HTTP/1.1\r\n" |
| 19227 | "Host: www.example.org\r\n" |
| 19228 | "Connection: keep-alive\r\n"), |
| 19229 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19230 | }; |
| 19231 | |
| 19232 | MockRead data_reads1[] = { |
| 19233 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 19234 | // Give a couple authenticate options (only the middle one is actually |
| 19235 | // supported). |
| 19236 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 19237 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19238 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 19239 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19240 | // Large content-length -- won't matter, as connection will be reset. |
| 19241 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 19242 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 19243 | }; |
| 19244 | |
| 19245 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19246 | // be issuing -- the final header line contains the credentials. |
| 19247 | MockWrite data_writes2[] = { |
| 19248 | MockWrite("GET / HTTP/1.1\r\n" |
| 19249 | "Host: www.example.org\r\n" |
| 19250 | "Connection: keep-alive\r\n" |
| 19251 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 19252 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19253 | }; |
| 19254 | |
| 19255 | // Lastly, the server responds with the actual content. |
| 19256 | MockRead data_reads2[] = { |
| 19257 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19258 | MockRead("hello world"), |
| 19259 | MockRead(SYNCHRONOUS, OK), |
| 19260 | }; |
| 19261 | |
| 19262 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19263 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19264 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19265 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19266 | |
| 19267 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19269 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19270 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19271 | |
| 19272 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19273 | base::TimeTicks restart_time; |
| 19274 | |
| 19275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19276 | auto trans = |
| 19277 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19278 | |
| 19279 | TestCompletionCallback callback1; |
| 19280 | |
| 19281 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19282 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19283 | |
| 19284 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19285 | |
| 19286 | TestCompletionCallback callback2; |
| 19287 | |
| 19288 | // Wait 10 ms then restart with auth |
| 19289 | FastForwardBy(kSleepDuration); |
| 19290 | restart_time = base::TimeTicks::Now(); |
| 19291 | rv = |
| 19292 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19293 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19294 | |
| 19295 | std::string response_data; |
| 19296 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19297 | EXPECT_EQ("hello world", response_data); |
| 19298 | |
| 19299 | trans.reset(); |
| 19300 | |
| 19301 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 19302 | // retry. Note that we don't report the error draining the body, as the first |
| 19303 | // request already generated a report for the auth challenge. |
| 19304 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 19305 | |
| 19306 | // Check error report contents |
| 19307 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 19308 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 19309 | |
| 19310 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19311 | network_error_logging_service()->errors()[0]; |
| 19312 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19313 | network_error_logging_service()->errors()[1]; |
| 19314 | |
| 19315 | // Sanity-check elapsed time values |
| 19316 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19317 | // Check that the start time is refreshed when restarting with auth. |
| 19318 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19319 | } |
| 19320 | |
| 19321 | // Same as above, except draining the body before restarting fails |
| 19322 | // asynchronously. |
| 19323 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19324 | CreateReportRestartWithAuthAsync) { |
| 19325 | std::string extra_header_string = extra_headers_.ToString(); |
| 19326 | static const base::TimeDelta kSleepDuration = |
| 19327 | base::TimeDelta::FromMilliseconds(10); |
| 19328 | |
| 19329 | MockWrite data_writes1[] = { |
| 19330 | MockWrite("GET / HTTP/1.1\r\n" |
| 19331 | "Host: www.example.org\r\n" |
| 19332 | "Connection: keep-alive\r\n"), |
| 19333 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19334 | }; |
| 19335 | |
| 19336 | MockRead data_reads1[] = { |
| 19337 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 19338 | // Give a couple authenticate options (only the middle one is actually |
| 19339 | // supported). |
| 19340 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 19341 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19342 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 19343 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19344 | // Large content-length -- won't matter, as connection will be reset. |
| 19345 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 19346 | MockRead(ASYNC, ERR_FAILED), |
| 19347 | }; |
| 19348 | |
| 19349 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19350 | // be issuing -- the final header line contains the credentials. |
| 19351 | MockWrite data_writes2[] = { |
| 19352 | MockWrite("GET / HTTP/1.1\r\n" |
| 19353 | "Host: www.example.org\r\n" |
| 19354 | "Connection: keep-alive\r\n" |
| 19355 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 19356 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19357 | }; |
| 19358 | |
| 19359 | // Lastly, the server responds with the actual content. |
| 19360 | MockRead data_reads2[] = { |
| 19361 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19362 | MockRead("hello world"), |
| 19363 | MockRead(SYNCHRONOUS, OK), |
| 19364 | }; |
| 19365 | |
| 19366 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19367 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19368 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19369 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19370 | |
| 19371 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19373 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19375 | |
| 19376 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 19377 | base::TimeTicks restart_time; |
| 19378 | |
| 19379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19380 | auto trans = |
| 19381 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19382 | |
| 19383 | TestCompletionCallback callback1; |
| 19384 | |
| 19385 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19386 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19387 | |
| 19388 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19389 | |
| 19390 | TestCompletionCallback callback2; |
| 19391 | |
| 19392 | // Wait 10 ms then restart with auth |
| 19393 | FastForwardBy(kSleepDuration); |
| 19394 | restart_time = base::TimeTicks::Now(); |
| 19395 | rv = |
| 19396 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19397 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19398 | |
| 19399 | std::string response_data; |
| 19400 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19401 | EXPECT_EQ("hello world", response_data); |
| 19402 | |
| 19403 | trans.reset(); |
| 19404 | |
| 19405 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 19406 | // retry. Note that we don't report the error draining the body, as the first |
| 19407 | // request already generated a report for the auth challenge. |
| 19408 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 19409 | |
| 19410 | // Check error report contents |
| 19411 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 19412 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 19413 | |
| 19414 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19415 | network_error_logging_service()->errors()[0]; |
| 19416 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19417 | network_error_logging_service()->errors()[1]; |
| 19418 | |
| 19419 | // Sanity-check elapsed time values |
| 19420 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 19421 | // Check that the start time is refreshed when restarting with auth. |
| 19422 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 19423 | } |
| 19424 | |
| 19425 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19426 | CreateReportRetryKeepAliveConnectionReset) { |
| 19427 | std::string extra_header_string = extra_headers_.ToString(); |
| 19428 | MockWrite data_writes1[] = { |
| 19429 | MockWrite("GET / HTTP/1.1\r\n" |
| 19430 | "Host: www.example.org\r\n" |
| 19431 | "Connection: keep-alive\r\n"), |
| 19432 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19433 | MockWrite("GET / HTTP/1.1\r\n" |
| 19434 | "Host: www.example.org\r\n" |
| 19435 | "Connection: keep-alive\r\n"), |
| 19436 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19437 | }; |
| 19438 | |
| 19439 | MockRead data_reads1[] = { |
| 19440 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19441 | MockRead("hello"), |
| 19442 | // Connection is reset |
| 19443 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 19444 | }; |
| 19445 | |
| 19446 | // Successful retry |
| 19447 | MockRead data_reads2[] = { |
| 19448 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19449 | MockRead("world"), |
| 19450 | MockRead(ASYNC, OK), |
| 19451 | }; |
| 19452 | |
| 19453 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19454 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19455 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19456 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19457 | |
| 19458 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19460 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19462 | |
| 19463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19464 | auto trans1 = |
| 19465 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19466 | |
| 19467 | TestCompletionCallback callback1; |
| 19468 | |
| 19469 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19470 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19471 | |
| 19472 | std::string response_data; |
| 19473 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19474 | EXPECT_EQ("hello", response_data); |
| 19475 | |
| 19476 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19477 | |
| 19478 | auto trans2 = |
| 19479 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19480 | |
| 19481 | TestCompletionCallback callback2; |
| 19482 | |
| 19483 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19484 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19485 | |
| 19486 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19487 | EXPECT_EQ("world", response_data); |
| 19488 | |
| 19489 | trans1.reset(); |
| 19490 | trans2.reset(); |
| 19491 | |
| 19492 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19493 | // the second request, then an OK report from the successful retry. |
| 19494 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19495 | |
| 19496 | // Check error report contents |
| 19497 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19498 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19499 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19500 | } |
| 19501 | |
| 19502 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19503 | CreateReportRetryKeepAlive408) { |
| 19504 | std::string extra_header_string = extra_headers_.ToString(); |
| 19505 | MockWrite data_writes1[] = { |
| 19506 | MockWrite("GET / HTTP/1.1\r\n" |
| 19507 | "Host: www.example.org\r\n" |
| 19508 | "Connection: keep-alive\r\n"), |
| 19509 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19510 | MockWrite("GET / HTTP/1.1\r\n" |
| 19511 | "Host: www.example.org\r\n" |
| 19512 | "Connection: keep-alive\r\n"), |
| 19513 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19514 | }; |
| 19515 | |
| 19516 | MockRead data_reads1[] = { |
| 19517 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19518 | MockRead("hello"), |
| 19519 | // 408 Request Timeout |
| 19520 | MockRead(SYNCHRONOUS, |
| 19521 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19522 | "Connection: Keep-Alive\r\n" |
| 19523 | "Content-Length: 6\r\n\r\n" |
| 19524 | "Pickle"), |
| 19525 | }; |
| 19526 | |
| 19527 | // Successful retry |
| 19528 | MockRead data_reads2[] = { |
| 19529 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19530 | MockRead("world"), |
| 19531 | MockRead(ASYNC, OK), |
| 19532 | }; |
| 19533 | |
| 19534 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19535 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19536 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19537 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19538 | |
| 19539 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19541 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19542 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19543 | |
| 19544 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19545 | auto trans1 = |
| 19546 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19547 | |
| 19548 | TestCompletionCallback callback1; |
| 19549 | |
| 19550 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19551 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19552 | |
| 19553 | std::string response_data; |
| 19554 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19555 | EXPECT_EQ("hello", response_data); |
| 19556 | |
| 19557 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19558 | |
| 19559 | auto trans2 = |
| 19560 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19561 | |
| 19562 | TestCompletionCallback callback2; |
| 19563 | |
| 19564 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19565 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19566 | |
| 19567 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19568 | EXPECT_EQ("world", response_data); |
| 19569 | |
| 19570 | trans1.reset(); |
| 19571 | trans2.reset(); |
| 19572 | |
| 19573 | // One 200 report from first request, then a 408 report from |
| 19574 | // the second request, then a 200 report from the successful retry. |
| 19575 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19576 | |
| 19577 | // Check error report contents |
| 19578 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19579 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19580 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19581 | } |
| 19582 | |
| 19583 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19584 | CreateReportRetry421WithoutConnectionPooling) { |
| 19585 | // Two hosts resolve to the same IP address. |
| 19586 | const std::string ip_addr = "1.2.3.4"; |
| 19587 | IPAddress ip; |
| 19588 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19589 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19590 | |
| 19591 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19592 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19593 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19594 | |
| 19595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19596 | |
| 19597 | // Two requests on the first connection. |
| 19598 | spdy::SpdySerializedFrame req1( |
| 19599 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19600 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19601 | spdy::SpdySerializedFrame req2( |
| 19602 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19603 | spdy::SpdySerializedFrame rst( |
| 19604 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19605 | MockWrite writes1[] = { |
| 19606 | CreateMockWrite(req1, 0), |
| 19607 | CreateMockWrite(req2, 3), |
| 19608 | CreateMockWrite(rst, 6), |
| 19609 | }; |
| 19610 | |
| 19611 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19612 | spdy::SpdySerializedFrame resp1( |
| 19613 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19614 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19615 | spdy::SpdyHeaderBlock response_headers; |
| 19616 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19617 | spdy::SpdySerializedFrame resp2( |
| 19618 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19619 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19620 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19621 | |
| 19622 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19623 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19624 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19625 | |
| 19626 | AddSSLSocketData(); |
| 19627 | |
| 19628 | // Retry the second request on a second connection. |
| 19629 | SpdyTestUtil spdy_util2; |
| 19630 | spdy::SpdySerializedFrame req3( |
| 19631 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19632 | MockWrite writes2[] = { |
| 19633 | CreateMockWrite(req3, 0), |
| 19634 | }; |
| 19635 | |
| 19636 | spdy::SpdySerializedFrame resp3( |
| 19637 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19638 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19639 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19640 | MockRead(ASYNC, 0, 3)}; |
| 19641 | |
| 19642 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19643 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19644 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19645 | |
| 19646 | AddSSLSocketData(); |
| 19647 | |
| 19648 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19649 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19650 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19651 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19652 | |
| 19653 | HttpRequestInfo request1; |
| 19654 | request1.method = "GET"; |
| 19655 | request1.url = GURL("https://www.example.org/"); |
| 19656 | request1.load_flags = 0; |
| 19657 | request1.traffic_annotation = |
| 19658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19659 | auto trans1 = |
| 19660 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19661 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19662 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19663 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19664 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19665 | |
| 19666 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19667 | ASSERT_TRUE(response); |
| 19668 | ASSERT_TRUE(response->headers); |
| 19669 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19670 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19671 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19672 | std::string response_data; |
| 19673 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19674 | EXPECT_EQ("hello!", response_data); |
| 19675 | |
| 19676 | trans1.reset(); |
| 19677 | |
| 19678 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19679 | |
| 19680 | HttpRequestInfo request2; |
| 19681 | request2.method = "GET"; |
| 19682 | request2.url = GURL("https://mail.example.org/"); |
| 19683 | request2.load_flags = 0; |
| 19684 | request2.traffic_annotation = |
| 19685 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19686 | auto trans2 = |
| 19687 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19688 | |
| 19689 | BoundTestNetLog log; |
| 19690 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19691 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19692 | |
| 19693 | response = trans2->GetResponseInfo(); |
| 19694 | ASSERT_TRUE(response); |
| 19695 | ASSERT_TRUE(response->headers); |
| 19696 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19697 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19698 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19699 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19700 | EXPECT_EQ("hello!", response_data); |
| 19701 | |
| 19702 | trans2.reset(); |
| 19703 | |
| 19704 | // One 200 report from the first request, then a 421 report from the |
| 19705 | // second request, then a 200 report from the successful retry. |
| 19706 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19707 | |
| 19708 | // Check error report contents |
| 19709 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19710 | network_error_logging_service()->errors()[0]; |
| 19711 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19712 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19713 | EXPECT_EQ("", error1.user_agent); |
| 19714 | EXPECT_EQ(ip, error1.server_ip); |
| 19715 | EXPECT_EQ("h2", error1.protocol); |
| 19716 | EXPECT_EQ("GET", error1.method); |
| 19717 | EXPECT_EQ(200, error1.status_code); |
| 19718 | EXPECT_EQ(OK, error1.type); |
| 19719 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19720 | |
| 19721 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19722 | network_error_logging_service()->errors()[1]; |
| 19723 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19724 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19725 | EXPECT_EQ("", error2.user_agent); |
| 19726 | EXPECT_EQ(ip, error2.server_ip); |
| 19727 | EXPECT_EQ("h2", error2.protocol); |
| 19728 | EXPECT_EQ("GET", error2.method); |
| 19729 | EXPECT_EQ(421, error2.status_code); |
| 19730 | EXPECT_EQ(OK, error2.type); |
| 19731 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19732 | |
| 19733 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19734 | network_error_logging_service()->errors()[2]; |
| 19735 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19736 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19737 | EXPECT_EQ("", error3.user_agent); |
| 19738 | EXPECT_EQ(ip, error3.server_ip); |
| 19739 | EXPECT_EQ("h2", error3.protocol); |
| 19740 | EXPECT_EQ("GET", error3.method); |
| 19741 | EXPECT_EQ(200, error3.status_code); |
| 19742 | EXPECT_EQ(OK, error3.type); |
| 19743 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19744 | } |
| 19745 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19746 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19747 | CreateReportCancelAfterStart) { |
| 19748 | StaticSocketDataProvider data; |
| 19749 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19751 | |
| 19752 | TestCompletionCallback callback; |
| 19753 | auto session = CreateSession(&session_deps_); |
| 19754 | auto trans = |
| 19755 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19756 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19757 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19758 | |
| 19759 | // Cancel after start. |
| 19760 | trans.reset(); |
| 19761 | |
| 19762 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19763 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19764 | IPAddress() /* server_ip */); |
| 19765 | } |
| 19766 | |
| 19767 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19768 | CreateReportCancelBeforeReadingBody) { |
| 19769 | std::string extra_header_string = extra_headers_.ToString(); |
| 19770 | MockWrite data_writes[] = { |
| 19771 | MockWrite("GET / HTTP/1.1\r\n" |
| 19772 | "Host: www.example.org\r\n" |
| 19773 | "Connection: keep-alive\r\n"), |
| 19774 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19775 | }; |
| 19776 | MockRead data_reads[] = { |
| 19777 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19778 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19779 | }; |
| 19780 | |
| 19781 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19783 | |
| 19784 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19786 | |
| 19787 | TestCompletionCallback callback; |
| 19788 | auto session = CreateSession(&session_deps_); |
| 19789 | auto trans = |
| 19790 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19791 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19792 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19793 | |
| 19794 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19795 | ASSERT_TRUE(response); |
| 19796 | |
| 19797 | EXPECT_TRUE(response->headers); |
| 19798 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19799 | |
| 19800 | // Cancel before reading the body. |
| 19801 | trans.reset(); |
| 19802 | |
| 19803 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19804 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19805 | } |
| 19806 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19807 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19808 | base::HistogramTester histograms; |
| 19809 | RequestPolicy(); |
| 19810 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19811 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19812 | |
| 19813 | // Make HTTP request |
| 19814 | std::string extra_header_string = extra_headers_.ToString(); |
| 19815 | MockRead data_reads[] = { |
| 19816 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19817 | MockRead("hello world"), |
| 19818 | MockRead(SYNCHRONOUS, OK), |
| 19819 | }; |
| 19820 | MockWrite data_writes[] = { |
| 19821 | MockWrite("GET / HTTP/1.1\r\n" |
| 19822 | "Host: www.example.org\r\n" |
| 19823 | "Connection: keep-alive\r\n"), |
| 19824 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19825 | }; |
| 19826 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19827 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19828 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19829 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19830 | // Insecure url |
| 19831 | url_ = "http://www.example.org/"; |
| 19832 | request_.url = GURL(url_); |
| 19833 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19834 | TestCompletionCallback callback; |
| 19835 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19836 | auto trans = |
| 19837 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19838 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19839 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19840 | |
| 19841 | std::string response_data; |
| 19842 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19843 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19844 | |
| 19845 | // Insecure request does not generate a report |
| 19846 | histograms.ExpectBucketCount( |
| 19847 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19848 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19849 | |
| 19850 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19851 | } |
| 19852 | |
| 19853 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19854 | DontCreateReportHttpError) { |
| 19855 | base::HistogramTester histograms; |
| 19856 | RequestPolicy(); |
| 19857 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19858 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19859 | |
| 19860 | // Make HTTP request that fails |
| 19861 | MockRead data_reads[] = { |
| 19862 | MockRead("hello world"), |
| 19863 | MockRead(SYNCHRONOUS, OK), |
| 19864 | }; |
| 19865 | |
| 19866 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19867 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19868 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19869 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19870 | request_.url = GURL(url_); |
| 19871 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19873 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19874 | auto trans = |
| 19875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19876 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19877 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19878 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19879 | |
| 19880 | // Insecure request does not generate a report, regardless of existence of a |
| 19881 | // policy for the origin. |
| 19882 | histograms.ExpectBucketCount( |
| 19883 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19884 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19885 | |
| 19886 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19887 | } |
| 19888 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19889 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19890 | // proxy. |
| 19891 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19892 | HttpRequestInfo request; |
| 19893 | request.method = "GET"; |
| 19894 | request.url = GURL("https://www.example.org/"); |
| 19895 | request.traffic_annotation = |
| 19896 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19897 | |
| 19898 | // Configure against proxy server "myproxy:70". |
| 19899 | session_deps_.proxy_resolution_service = |
| 19900 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19901 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19903 | |
| 19904 | // Since we have proxy, should try to establish tunnel. |
| 19905 | MockWrite data_writes1[] = { |
| 19906 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19907 | "Host: www.example.org:443\r\n" |
| 19908 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19909 | }; |
| 19910 | |
| 19911 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19912 | // connection. |
| 19913 | MockRead data_reads1[] = { |
| 19914 | // No credentials. |
| 19915 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19916 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19917 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19918 | }; |
| 19919 | |
| 19920 | MockWrite data_writes2[] = { |
| 19921 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19922 | // be issuing -- the final header line contains the credentials. |
| 19923 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19924 | "Host: www.example.org:443\r\n" |
| 19925 | "Proxy-Connection: keep-alive\r\n" |
| 19926 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19927 | |
| 19928 | MockWrite("GET / HTTP/1.1\r\n" |
| 19929 | "Host: www.example.org\r\n" |
| 19930 | "Connection: keep-alive\r\n\r\n"), |
| 19931 | }; |
| 19932 | |
| 19933 | MockRead data_reads2[] = { |
| 19934 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19935 | |
| 19936 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19938 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19939 | MockRead(SYNCHRONOUS, "hello"), |
| 19940 | }; |
| 19941 | |
| 19942 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19943 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19944 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19945 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19946 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19948 | |
| 19949 | TestCompletionCallback callback1; |
| 19950 | |
| 19951 | auto trans = |
| 19952 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19953 | |
| 19954 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19955 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19956 | |
| 19957 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19958 | EXPECT_EQ(407, response->headers->response_code()); |
| 19959 | |
| 19960 | std::string response_data; |
| 19961 | rv = ReadTransaction(trans.get(), &response_data); |
| 19962 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19963 | |
| 19964 | // No NEL report is generated for the 407. |
| 19965 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19966 | |
| 19967 | TestCompletionCallback callback2; |
| 19968 | |
| 19969 | rv = |
| 19970 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19971 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19972 | |
| 19973 | response = trans->GetResponseInfo(); |
| 19974 | EXPECT_EQ(200, response->headers->response_code()); |
| 19975 | |
| 19976 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19977 | EXPECT_EQ("hello", response_data); |
| 19978 | |
| 19979 | trans.reset(); |
| 19980 | |
| 19981 | // No NEL report is generated because we are behind a proxy. |
| 19982 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19983 | } |
| 19984 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19985 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19986 | ReportContainsUploadDepth) { |
| 19987 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19988 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19989 | RequestPolicy(); |
| 19990 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19991 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19992 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19993 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19994 | } |
| 19995 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19996 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19997 | std::string extra_header_string = extra_headers_.ToString(); |
| 19998 | static const base::TimeDelta kSleepDuration = |
| 19999 | base::TimeDelta::FromMilliseconds(10); |
| 20000 | |
| 20001 | std::vector<MockWrite> data_writes = { |
| 20002 | MockWrite(ASYNC, 0, |
| 20003 | "GET / HTTP/1.1\r\n" |
| 20004 | "Host: www.example.org\r\n" |
| 20005 | "Connection: keep-alive\r\n"), |
| 20006 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 20007 | }; |
| 20008 | |
| 20009 | std::vector<MockRead> data_reads = { |
| 20010 | // Write one byte of the status line, followed by a pause. |
| 20011 | MockRead(ASYNC, 2, "H"), |
| 20012 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 20013 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 20014 | MockRead(ASYNC, 5, "hello world"), |
| 20015 | MockRead(SYNCHRONOUS, OK, 6), |
| 20016 | }; |
| 20017 | |
| 20018 | SequencedSocketData data(data_reads, data_writes); |
| 20019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20020 | |
| 20021 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 20022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20023 | |
| 20024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20025 | |
| 20026 | auto trans = |
| 20027 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20028 | |
| 20029 | TestCompletionCallback callback; |
| 20030 | |
| 20031 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 20032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20033 | |
| 20034 | data.RunUntilPaused(); |
| 20035 | ASSERT_TRUE(data.IsPaused()); |
| 20036 | FastForwardBy(kSleepDuration); |
| 20037 | data.Resume(); |
| 20038 | |
| 20039 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 20040 | |
| 20041 | std::string response_data; |
| 20042 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 20043 | EXPECT_EQ("hello world", response_data); |
| 20044 | |
| 20045 | trans.reset(); |
| 20046 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20047 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20048 | |
| 20049 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 20050 | |
| 20051 | const NetworkErrorLoggingService::RequestDetails& error = |
| 20052 | network_error_logging_service()->errors()[0]; |
| 20053 | |
| 20054 | // Sanity-check elapsed time in error report |
| 20055 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 20056 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 20057 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 20058 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 20059 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 20060 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 20061 | HttpRequestInfo request; |
| 20062 | request.method = "GET"; |
| 20063 | request.url = GURL("http://example.org/"); |
| 20064 | |
| 20065 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 20066 | |
| 20067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 20069 | TestCompletionCallback callback1; |
| 20070 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 20071 | |
| 20072 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 20073 | } |
| 20074 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20075 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 20076 | HttpRequestInfo request; |
| 20077 | request.method = "GET"; |
| 20078 | request.url = GURL("https://www.example.org/"); |
| 20079 | request.traffic_annotation = |
| 20080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20081 | |
| 20082 | MockWrite data_writes[] = { |
| 20083 | MockWrite("GET / HTTP/1.1\r\n" |
| 20084 | "Host: www.example.org\r\n" |
| 20085 | "Connection: keep-alive\r\n\r\n"), |
| 20086 | }; |
| 20087 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20088 | MockRead data_reads[] = { |
| 20089 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20090 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20091 | MockRead(SYNCHRONOUS, "1"), |
| 20092 | }; |
| 20093 | |
| 20094 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20095 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20096 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20097 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20098 | session_deps_.enable_early_data = true; |
| 20099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20100 | |
| 20101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20102 | |
| 20103 | TestCompletionCallback callback; |
| 20104 | auto trans = |
| 20105 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20106 | |
| 20107 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20109 | |
| 20110 | rv = callback.WaitForResult(); |
| 20111 | EXPECT_THAT(rv, IsOk()); |
| 20112 | |
| 20113 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20114 | ASSERT_TRUE(response); |
| 20115 | ASSERT_TRUE(response->headers); |
| 20116 | EXPECT_EQ(200, response->headers->response_code()); |
| 20117 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20118 | |
| 20119 | // Check that ConfirmHandshake wasn't called. |
| 20120 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 20121 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 20122 | |
| 20123 | trans.reset(); |
| 20124 | |
| 20125 | session->CloseAllConnections(); |
| 20126 | } |
| 20127 | |
| 20128 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 20129 | HttpRequestInfo request; |
| 20130 | request.method = "POST"; |
| 20131 | request.url = GURL("https://www.example.org/"); |
| 20132 | request.traffic_annotation = |
| 20133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20134 | |
| 20135 | MockWrite data_writes[] = { |
| 20136 | MockWrite(SYNCHRONOUS, |
| 20137 | "POST / HTTP/1.1\r\n" |
| 20138 | "Host: www.example.org\r\n" |
| 20139 | "Connection: keep-alive\r\n" |
| 20140 | "Content-Length: 0\r\n\r\n"), |
| 20141 | }; |
| 20142 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20143 | MockRead data_reads[] = { |
| 20144 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20145 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20146 | MockRead(SYNCHRONOUS, "1"), |
| 20147 | }; |
| 20148 | |
| 20149 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20150 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20151 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20152 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20153 | session_deps_.enable_early_data = true; |
| 20154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20155 | |
| 20156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20157 | |
| 20158 | TestCompletionCallback callback; |
| 20159 | auto trans = |
| 20160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20161 | |
| 20162 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20164 | |
| 20165 | rv = callback.WaitForResult(); |
| 20166 | EXPECT_THAT(rv, IsOk()); |
| 20167 | |
| 20168 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20169 | ASSERT_TRUE(response); |
| 20170 | ASSERT_TRUE(response->headers); |
| 20171 | EXPECT_EQ(200, response->headers->response_code()); |
| 20172 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20173 | |
| 20174 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20175 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20176 | |
| 20177 | trans.reset(); |
| 20178 | |
| 20179 | session->CloseAllConnections(); |
| 20180 | } |
| 20181 | |
| 20182 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 20183 | HttpRequestInfo request; |
| 20184 | request.method = "POST"; |
| 20185 | request.url = GURL("https://www.example.org/"); |
| 20186 | request.traffic_annotation = |
| 20187 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20188 | |
| 20189 | MockWrite data_writes[] = { |
| 20190 | MockWrite(ASYNC, |
| 20191 | "POST / HTTP/1.1\r\n" |
| 20192 | "Host: www.example.org\r\n" |
| 20193 | "Connection: keep-alive\r\n" |
| 20194 | "Content-Length: 0\r\n\r\n"), |
| 20195 | }; |
| 20196 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20197 | MockRead data_reads[] = { |
| 20198 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20199 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20200 | MockRead(SYNCHRONOUS, "1"), |
| 20201 | }; |
| 20202 | |
| 20203 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20204 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20205 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20206 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 20207 | session_deps_.enable_early_data = true; |
| 20208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20209 | |
| 20210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20211 | |
| 20212 | TestCompletionCallback callback; |
| 20213 | auto trans = |
| 20214 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20215 | |
| 20216 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20218 | |
| 20219 | rv = callback.WaitForResult(); |
| 20220 | EXPECT_THAT(rv, IsOk()); |
| 20221 | |
| 20222 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20223 | ASSERT_TRUE(response); |
| 20224 | ASSERT_TRUE(response->headers); |
| 20225 | EXPECT_EQ(200, response->headers->response_code()); |
| 20226 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20227 | |
| 20228 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20229 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20230 | |
| 20231 | trans.reset(); |
| 20232 | |
| 20233 | session->CloseAllConnections(); |
| 20234 | } |
| 20235 | |
| 20236 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 20237 | HttpRequestInfo request; |
| 20238 | request.method = "POST"; |
| 20239 | request.url = GURL("https://www.example.org/"); |
| 20240 | request.traffic_annotation = |
| 20241 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20242 | |
| 20243 | MockWrite data_writes[] = { |
| 20244 | MockWrite(SYNCHRONOUS, |
| 20245 | "POST / HTTP/1.1\r\n" |
| 20246 | "Host: www.example.org\r\n" |
| 20247 | "Connection: keep-alive\r\n" |
| 20248 | "Content-Length: 0\r\n\r\n"), |
| 20249 | }; |
| 20250 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20251 | MockRead data_reads[] = { |
| 20252 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20253 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20254 | MockRead(SYNCHRONOUS, "1"), |
| 20255 | }; |
| 20256 | |
| 20257 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20259 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20260 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 20261 | session_deps_.enable_early_data = true; |
| 20262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20263 | |
| 20264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20265 | |
| 20266 | TestCompletionCallback callback; |
| 20267 | auto trans = |
| 20268 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20269 | |
| 20270 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20272 | |
| 20273 | rv = callback.WaitForResult(); |
| 20274 | EXPECT_THAT(rv, IsOk()); |
| 20275 | |
| 20276 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20277 | ASSERT_TRUE(response); |
| 20278 | ASSERT_TRUE(response->headers); |
| 20279 | EXPECT_EQ(200, response->headers->response_code()); |
| 20280 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20281 | |
| 20282 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20283 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20284 | |
| 20285 | trans.reset(); |
| 20286 | |
| 20287 | session->CloseAllConnections(); |
| 20288 | } |
| 20289 | |
| 20290 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 20291 | HttpRequestInfo request; |
| 20292 | request.method = "POST"; |
| 20293 | request.url = GURL("https://www.example.org/"); |
| 20294 | request.traffic_annotation = |
| 20295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20296 | |
| 20297 | MockWrite data_writes[] = { |
| 20298 | MockWrite(ASYNC, |
| 20299 | "POST / HTTP/1.1\r\n" |
| 20300 | "Host: www.example.org\r\n" |
| 20301 | "Connection: keep-alive\r\n" |
| 20302 | "Content-Length: 0\r\n\r\n"), |
| 20303 | }; |
| 20304 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20305 | MockRead data_reads[] = { |
| 20306 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20307 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20308 | MockRead(SYNCHRONOUS, "1"), |
| 20309 | }; |
| 20310 | |
| 20311 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20312 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20313 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20314 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 20315 | session_deps_.enable_early_data = true; |
| 20316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20317 | |
| 20318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20319 | |
| 20320 | TestCompletionCallback callback; |
| 20321 | auto trans = |
| 20322 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20323 | |
| 20324 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20326 | |
| 20327 | rv = callback.WaitForResult(); |
| 20328 | EXPECT_THAT(rv, IsOk()); |
| 20329 | |
| 20330 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20331 | ASSERT_TRUE(response); |
| 20332 | ASSERT_TRUE(response->headers); |
| 20333 | EXPECT_EQ(200, response->headers->response_code()); |
| 20334 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 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 | |
David Benjamin | fb97693 | 2019-05-15 13:39:15 | [diff] [blame] | 20344 | // 0-RTT rejects are handled at HttpNetworkTransaction. |
| 20345 | TEST_F(HttpNetworkTransactionTest, ZeroRTTReject) { |
| 20346 | enum class RejectType { |
| 20347 | kRead, |
| 20348 | kWrite, |
| 20349 | kConfirm, |
| 20350 | }; |
| 20351 | |
| 20352 | for (RejectType type : |
| 20353 | {RejectType::kRead, RejectType::kWrite, RejectType::kConfirm}) { |
| 20354 | SCOPED_TRACE(static_cast<int>(type)); |
| 20355 | for (Error reject_error : |
| 20356 | {ERR_EARLY_DATA_REJECTED, ERR_WRONG_VERSION_ON_EARLY_DATA}) { |
| 20357 | SCOPED_TRACE(reject_error); |
| 20358 | session_deps_.socket_factory = |
| 20359 | std::make_unique<MockClientSocketFactory>(); |
| 20360 | |
| 20361 | HttpRequestInfo request; |
| 20362 | request.method = type == RejectType::kConfirm ? "POST" : "GET"; |
| 20363 | request.url = GURL("https://www.example.org/"); |
| 20364 | request.traffic_annotation = |
| 20365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20366 | |
| 20367 | // The first request fails. |
| 20368 | std::vector<MockWrite> data1_writes; |
| 20369 | std::vector<MockRead> data1_reads; |
| 20370 | SSLSocketDataProvider ssl1(SYNCHRONOUS, OK); |
| 20371 | switch (type) { |
| 20372 | case RejectType::kRead: |
| 20373 | data1_writes.emplace_back( |
| 20374 | "GET / HTTP/1.1\r\n" |
| 20375 | "Host: www.example.org\r\n" |
| 20376 | "Connection: keep-alive\r\n\r\n"); |
| 20377 | data1_reads.emplace_back(ASYNC, reject_error); |
| 20378 | // Cause ConfirmHandshake to hang (it should not be called). |
| 20379 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 20380 | break; |
| 20381 | case RejectType::kWrite: |
| 20382 | data1_writes.emplace_back(ASYNC, reject_error); |
| 20383 | // Cause ConfirmHandshake to hang (it should not be called). |
| 20384 | ssl1.confirm = MockConfirm(SYNCHRONOUS, ERR_IO_PENDING); |
| 20385 | break; |
| 20386 | case RejectType::kConfirm: |
| 20387 | // The request never gets far enough to read or write. |
| 20388 | ssl1.confirm = MockConfirm(ASYNC, reject_error); |
| 20389 | break; |
| 20390 | } |
| 20391 | |
| 20392 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
| 20393 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20394 | session_deps_.enable_early_data = true; |
| 20395 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 20396 | |
| 20397 | // The retry succeeds. |
| 20398 | // |
| 20399 | // TODO(https://crbug.com/950705): If |reject_error| is |
| 20400 | // ERR_EARLY_DATA_REJECTED, the retry should happen over the same socket. |
| 20401 | MockWrite data2_writes[] = { |
| 20402 | request.method == "POST" |
| 20403 | ? MockWrite("POST / HTTP/1.1\r\n" |
| 20404 | "Host: www.example.org\r\n" |
| 20405 | "Connection: keep-alive\r\n" |
| 20406 | "Content-Length: 0\r\n\r\n") |
| 20407 | : MockWrite("GET / HTTP/1.1\r\n" |
| 20408 | "Host: www.example.org\r\n" |
| 20409 | "Connection: keep-alive\r\n\r\n"), |
| 20410 | }; |
| 20411 | |
| 20412 | MockRead data2_reads[] = { |
| 20413 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20414 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20415 | MockRead(SYNCHRONOUS, "1"), |
| 20416 | }; |
| 20417 | |
| 20418 | StaticSocketDataProvider data2(data2_reads, data2_writes); |
| 20419 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20420 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 20421 | ssl2.confirm = MockConfirm(ASYNC, OK); |
| 20422 | session_deps_.enable_early_data = true; |
| 20423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 20424 | |
| 20425 | std::unique_ptr<HttpNetworkSession> session( |
| 20426 | CreateSession(&session_deps_)); |
| 20427 | |
| 20428 | TestCompletionCallback callback; |
| 20429 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 20430 | session.get()); |
| 20431 | |
| 20432 | EXPECT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20433 | NetLogWithSource())), |
| 20434 | IsOk()); |
| 20435 | |
| 20436 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 20437 | ASSERT_TRUE(response); |
| 20438 | ASSERT_TRUE(response->headers); |
| 20439 | EXPECT_EQ(200, response->headers->response_code()); |
| 20440 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 20441 | } |
| 20442 | } |
| 20443 | } |
| 20444 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20445 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 20446 | HttpRequestInfo request; |
| 20447 | request.method = "POST"; |
| 20448 | request.url = GURL("https://www.example.org/"); |
| 20449 | request.traffic_annotation = |
| 20450 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20451 | |
| 20452 | MockWrite data_writes[] = { |
| 20453 | MockWrite("POST / HTTP/1.1\r\n" |
| 20454 | "Host: www.example.org\r\n" |
| 20455 | "Connection: keep-alive\r\n" |
| 20456 | "Content-Length: 0\r\n\r\n"), |
| 20457 | }; |
| 20458 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20459 | MockRead data_reads[] = { |
| 20460 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20461 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20462 | MockRead(SYNCHRONOUS, "1"), |
| 20463 | }; |
| 20464 | |
| 20465 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20467 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20468 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 20469 | session_deps_.enable_early_data = true; |
| 20470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20471 | |
| 20472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20473 | |
| 20474 | TestCompletionCallback callback; |
| 20475 | auto trans = |
| 20476 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20477 | |
| 20478 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20480 | |
| 20481 | rv = callback.WaitForResult(); |
| 20482 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20483 | |
| 20484 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20485 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20486 | |
| 20487 | trans.reset(); |
| 20488 | |
| 20489 | session->CloseAllConnections(); |
| 20490 | } |
| 20491 | |
| 20492 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 20493 | HttpRequestInfo request; |
| 20494 | request.method = "POST"; |
| 20495 | request.url = GURL("https://www.example.org/"); |
| 20496 | request.traffic_annotation = |
| 20497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20498 | |
| 20499 | MockWrite data_writes[] = { |
| 20500 | MockWrite("POST / HTTP/1.1\r\n" |
| 20501 | "Host: www.example.org\r\n" |
| 20502 | "Connection: keep-alive\r\n" |
| 20503 | "Content-Length: 0\r\n\r\n"), |
| 20504 | }; |
| 20505 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 20506 | MockRead data_reads[] = { |
| 20507 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 20508 | MockRead("Content-Length: 1\r\n\r\n"), |
| 20509 | MockRead(SYNCHRONOUS, "1"), |
| 20510 | }; |
| 20511 | |
| 20512 | StaticSocketDataProvider data(data_reads, data_writes); |
| 20513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 20514 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 20515 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 20516 | session_deps_.enable_early_data = true; |
| 20517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 20518 | |
| 20519 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20520 | |
| 20521 | TestCompletionCallback callback; |
| 20522 | auto trans = |
| 20523 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20524 | |
| 20525 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 20526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 20527 | |
| 20528 | rv = callback.WaitForResult(); |
| 20529 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 20530 | |
| 20531 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 20532 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 20533 | |
| 20534 | trans.reset(); |
| 20535 | |
| 20536 | session->CloseAllConnections(); |
| 20537 | } |
| 20538 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20539 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20540 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 20541 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 20542 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20543 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20544 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20545 | |
| 20546 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20547 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20548 | |
| 20549 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20550 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20551 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20552 | ASSERT_TRUE(identity_proxy); |
| 20553 | |
| 20554 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20555 | cert_request_info_origin->host_and_port = |
| 20556 | HostPortPair("www.example.org", 443); |
| 20557 | |
| 20558 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20559 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20560 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20561 | ASSERT_TRUE(identity_origin); |
| 20562 | |
| 20563 | HttpRequestInfo request; |
| 20564 | request.method = "GET"; |
| 20565 | request.url = GURL("https://www.example.org/"); |
| 20566 | request.traffic_annotation = |
| 20567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20568 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20569 | // First, the client connects to the proxy, which requests a client |
| 20570 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20571 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20572 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20573 | ssl_proxy1.expected_send_client_cert = false; |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20574 | StaticSocketDataProvider data1; |
| 20575 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20577 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20578 | // The client responds with a certificate on a new connection. The handshake |
| 20579 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20580 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20581 | ssl_proxy2.expected_send_client_cert = true; |
| 20582 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20583 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20584 | std::vector<MockWrite> mock_writes2; |
| 20585 | std::vector<MockRead> mock_reads2; |
| 20586 | mock_writes2.emplace_back( |
| 20587 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20588 | "Host: www.example.org:443\r\n" |
| 20589 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20590 | mock_reads2.emplace_back( |
| 20591 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20592 | "Content-Length: 0\r\n" |
| 20593 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20594 | // The client retries with credentials. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20595 | mock_writes2.emplace_back( |
| 20596 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20597 | "Host: www.example.org:443\r\n" |
| 20598 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20599 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20600 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20601 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20602 | // The origin requests client certificates. |
| 20603 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20604 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20605 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20606 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20609 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20610 | // The client responds to the origin client certificate request on a new |
| 20611 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20612 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20613 | ssl_proxy3.expected_send_client_cert = true; |
| 20614 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20615 | std::vector<MockWrite> mock_writes3; |
| 20616 | std::vector<MockRead> mock_reads3; |
| 20617 | mock_writes3.emplace_back( |
| 20618 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20619 | "Host: www.example.org:443\r\n" |
| 20620 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20621 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20622 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20623 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20624 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 20625 | ssl_origin3.expected_send_client_cert = true; |
| 20626 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20627 | // The client sends the origin HTTP request, which results in another HTTP |
| 20628 | // auth request. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20629 | mock_writes3.emplace_back( |
| 20630 | "GET / HTTP/1.1\r\n" |
| 20631 | "Host: www.example.org\r\n" |
| 20632 | "Connection: keep-alive\r\n\r\n"); |
| 20633 | mock_reads3.emplace_back( |
| 20634 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20635 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20636 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20637 | // The client retries with credentials, and the request finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20638 | mock_writes3.emplace_back( |
| 20639 | "GET / HTTP/1.1\r\n" |
| 20640 | "Host: www.example.org\r\n" |
| 20641 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20642 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20643 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20644 | mock_reads3.emplace_back( |
| 20645 | "HTTP/1.1 200 OK\r\n" |
| 20646 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20647 | // The client makes another request. This should reuse the socket with all |
| 20648 | // credentials cached. |
| 20649 | mock_writes3.emplace_back( |
| 20650 | "GET / HTTP/1.1\r\n" |
| 20651 | "Host: www.example.org\r\n" |
| 20652 | "Connection: keep-alive\r\n" |
| 20653 | // Authenticate as user:pass. |
| 20654 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20655 | mock_reads3.emplace_back( |
| 20656 | "HTTP/1.1 200 OK\r\n" |
| 20657 | "Content-Length: 0\r\n\r\n"); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20658 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20659 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20661 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20662 | |
| 20663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20664 | |
| 20665 | // Start the request. |
| 20666 | TestCompletionCallback callback; |
| 20667 | auto trans = |
| 20668 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20669 | int rv = callback.GetResult( |
| 20670 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20671 | |
| 20672 | // Handle the proxy client certificate challenge. |
| 20673 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20674 | SSLCertRequestInfo* cert_request_info = |
| 20675 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20676 | ASSERT_TRUE(cert_request_info); |
| 20677 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20678 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20679 | cert_request_info_proxy->host_and_port); |
| 20680 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20681 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20682 | callback.callback())); |
| 20683 | |
| 20684 | // Handle the proxy HTTP auth challenge. |
| 20685 | ASSERT_THAT(rv, IsOk()); |
| 20686 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20687 | EXPECT_TRUE( |
| 20688 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20689 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20690 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20691 | callback.callback())); |
| 20692 | |
| 20693 | // Handle the origin client certificate challenge. |
| 20694 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20695 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20696 | ASSERT_TRUE(cert_request_info); |
| 20697 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20698 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20699 | cert_request_info_origin->host_and_port); |
| 20700 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20701 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20702 | callback.callback())); |
| 20703 | |
| 20704 | // Handle the origin HTTP auth challenge. |
| 20705 | ASSERT_THAT(rv, IsOk()); |
| 20706 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20707 | EXPECT_TRUE( |
| 20708 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20709 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20710 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20711 | callback.callback())); |
| 20712 | |
| 20713 | // The request completes. |
| 20714 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20715 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20716 | |
| 20717 | // Make a second request. This time all credentials are cached. |
| 20718 | trans = |
| 20719 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20720 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20721 | NetLogWithSource())), |
| 20722 | IsOk()); |
| 20723 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20724 | } |
| 20725 | |
| 20726 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20727 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 20728 | // test for https://crbug.com/946406. |
| 20729 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 20730 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20731 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20732 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20733 | |
| 20734 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20735 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20736 | |
| 20737 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20738 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20739 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20740 | ASSERT_TRUE(identity_proxy); |
| 20741 | |
| 20742 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20743 | cert_request_info_origin->host_and_port = |
| 20744 | HostPortPair("www.example.org", 443); |
| 20745 | |
| 20746 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20747 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20748 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20749 | ASSERT_TRUE(identity_origin); |
| 20750 | |
| 20751 | HttpRequestInfo request; |
| 20752 | request.method = "GET"; |
| 20753 | request.url = GURL("https://www.example.org/"); |
| 20754 | request.traffic_annotation = |
| 20755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20756 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20757 | // First, the client connects to the proxy, which requests a client |
| 20758 | // certificate. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20759 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20760 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20761 | ssl_proxy1.expected_send_client_cert = false; |
| 20762 | StaticSocketDataProvider data1; |
| 20763 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20765 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20766 | // The client responds with a certificate on a new connection. The handshake |
| 20767 | // succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20768 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20769 | ssl_proxy2.expected_send_client_cert = true; |
| 20770 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20771 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20772 | std::vector<MockWrite> mock_writes2; |
| 20773 | std::vector<MockRead> mock_reads2; |
| 20774 | mock_writes2.emplace_back( |
| 20775 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20776 | "Host: www.example.org:443\r\n" |
| 20777 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20778 | mock_reads2.emplace_back( |
| 20779 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20780 | "Content-Length: 0\r\n" |
| 20781 | "Proxy-Connection: close\r\n" |
| 20782 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20783 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20784 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20786 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20787 | // The client retries with credentials on a new connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20788 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20789 | ssl_proxy3.expected_send_client_cert = true; |
| 20790 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 20791 | std::vector<MockWrite> mock_writes3; |
| 20792 | std::vector<MockRead> mock_reads3; |
| 20793 | mock_writes3.emplace_back( |
| 20794 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20795 | "Host: www.example.org:443\r\n" |
| 20796 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20797 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20798 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20799 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20800 | // The origin requests client certificates. |
| 20801 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20802 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 20803 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20804 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20807 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20808 | // The client responds to the origin client certificate request on a new |
| 20809 | // connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20810 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 20811 | ssl_proxy4.expected_send_client_cert = true; |
| 20812 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 20813 | std::vector<MockWrite> mock_writes4; |
| 20814 | std::vector<MockRead> mock_reads4; |
| 20815 | mock_writes4.emplace_back( |
| 20816 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20817 | "Host: www.example.org:443\r\n" |
| 20818 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20819 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20820 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20821 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20822 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 20823 | ssl_origin4.expected_send_client_cert = true; |
| 20824 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20825 | // The client sends the origin HTTP request, which results in another HTTP |
| 20826 | // auth request and closed connection. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20827 | mock_writes4.emplace_back( |
| 20828 | "GET / HTTP/1.1\r\n" |
| 20829 | "Host: www.example.org\r\n" |
| 20830 | "Connection: keep-alive\r\n\r\n"); |
| 20831 | mock_reads4.emplace_back( |
| 20832 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20833 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20834 | "Connection: close\r\n" |
| 20835 | "Content-Length: 0\r\n\r\n"); |
| 20836 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 20837 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20838 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 20839 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20840 | |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20841 | // The client retries with credentials on a new connection, and the request |
| 20842 | // finally succeeds. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20843 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 20844 | ssl_proxy5.expected_send_client_cert = true; |
| 20845 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 20846 | std::vector<MockWrite> mock_writes5; |
| 20847 | std::vector<MockRead> mock_reads5; |
| 20848 | mock_writes5.emplace_back( |
| 20849 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20850 | "Host: www.example.org:443\r\n" |
| 20851 | "Proxy-Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20852 | // Authenticate as proxyuser:proxypass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20853 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20854 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20855 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 20856 | ssl_origin5.expected_send_client_cert = true; |
| 20857 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 20858 | mock_writes5.emplace_back( |
| 20859 | "GET / HTTP/1.1\r\n" |
| 20860 | "Host: www.example.org\r\n" |
| 20861 | "Connection: keep-alive\r\n" |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20862 | // Authenticate as user:pass. |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20863 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20864 | mock_reads5.emplace_back( |
| 20865 | "HTTP/1.1 200 OK\r\n" |
| 20866 | "Connection: close\r\n" |
| 20867 | "Content-Length: 0\r\n\r\n"); |
| 20868 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 20869 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 20871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20872 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20873 | // The client makes a second request. This needs yet another connection, but |
| 20874 | // all credentials are cached. |
| 20875 | SSLSocketDataProvider ssl_proxy6(ASYNC, OK); |
| 20876 | ssl_proxy6.expected_send_client_cert = true; |
| 20877 | ssl_proxy6.expected_client_cert = identity_proxy->certificate(); |
| 20878 | std::vector<MockWrite> mock_writes6; |
| 20879 | std::vector<MockRead> mock_reads6; |
| 20880 | mock_writes6.emplace_back( |
| 20881 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20882 | "Host: www.example.org:443\r\n" |
| 20883 | "Proxy-Connection: keep-alive\r\n" |
| 20884 | // Authenticate as proxyuser:proxypass. |
| 20885 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20886 | mock_reads6.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20887 | SSLSocketDataProvider ssl_origin6(ASYNC, OK); |
| 20888 | ssl_origin6.expected_send_client_cert = true; |
| 20889 | ssl_origin6.expected_client_cert = identity_origin->certificate(); |
| 20890 | mock_writes6.emplace_back( |
| 20891 | "GET / HTTP/1.1\r\n" |
| 20892 | "Host: www.example.org\r\n" |
| 20893 | "Connection: keep-alive\r\n" |
| 20894 | // Authenticate as user:pass. |
| 20895 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20896 | mock_reads6.emplace_back( |
| 20897 | "HTTP/1.1 200 OK\r\n" |
| 20898 | "Connection: close\r\n" |
| 20899 | "Content-Length: 0\r\n\r\n"); |
| 20900 | StaticSocketDataProvider data6(mock_reads6, mock_writes6); |
| 20901 | session_deps_.socket_factory->AddSocketDataProvider(&data6); |
| 20902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy6); |
| 20903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin6); |
| 20904 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 20905 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20906 | |
| 20907 | // Start the request. |
| 20908 | TestCompletionCallback callback; |
| 20909 | auto trans = |
| 20910 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20911 | int rv = callback.GetResult( |
| 20912 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20913 | |
| 20914 | // Handle the proxy client certificate challenge. |
| 20915 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20916 | SSLCertRequestInfo* cert_request_info = |
| 20917 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20918 | ASSERT_TRUE(cert_request_info); |
| 20919 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20920 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20921 | cert_request_info_proxy->host_and_port); |
| 20922 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20923 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20924 | callback.callback())); |
| 20925 | |
| 20926 | // Handle the proxy HTTP auth challenge. |
| 20927 | ASSERT_THAT(rv, IsOk()); |
| 20928 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20929 | EXPECT_TRUE( |
| 20930 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20931 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20932 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20933 | callback.callback())); |
| 20934 | |
| 20935 | // Handle the origin client certificate challenge. |
| 20936 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20937 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20938 | ASSERT_TRUE(cert_request_info); |
| 20939 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20940 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20941 | cert_request_info_origin->host_and_port); |
| 20942 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20943 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20944 | callback.callback())); |
| 20945 | |
| 20946 | // Handle the origin HTTP auth challenge. |
| 20947 | ASSERT_THAT(rv, IsOk()); |
| 20948 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20949 | EXPECT_TRUE( |
| 20950 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20951 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20952 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20953 | callback.callback())); |
| 20954 | |
| 20955 | // The request completes. |
| 20956 | ASSERT_THAT(rv, IsOk()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20957 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 20958 | |
| 20959 | // Make a second request. This time all credentials are cached. |
| 20960 | trans = |
| 20961 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20962 | ASSERT_THAT(callback.GetResult(trans->Start(&request, callback.callback(), |
| 20963 | NetLogWithSource())), |
| 20964 | IsOk()); |
| 20965 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 7ebab03 | 2019-04-30 21:51:30 | [diff] [blame] | 20966 | } |
| 20967 | |
| 20968 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 20969 | // certificates. This is a regression test for https://crbug.com/946406. |
| 20970 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 20971 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20972 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20973 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20974 | |
| 20975 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20976 | cert_request_info_origin->host_and_port = |
| 20977 | HostPortPair("www.example.org", 443); |
| 20978 | |
| 20979 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20980 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20981 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20982 | ASSERT_TRUE(identity_origin); |
| 20983 | |
| 20984 | HttpRequestInfo request; |
| 20985 | request.method = "GET"; |
| 20986 | request.url = GURL("https://www.example.org/"); |
| 20987 | request.traffic_annotation = |
| 20988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20989 | |
| 20990 | // The client connects to the proxy. The handshake succeeds. |
| 20991 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 20992 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20993 | std::vector<MockWrite> mock_writes1; |
| 20994 | std::vector<MockRead> mock_reads1; |
| 20995 | mock_writes1.emplace_back( |
| 20996 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20997 | "Host: www.example.org:443\r\n" |
| 20998 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20999 | mock_reads1.emplace_back( |
| 21000 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 21001 | "Content-Length: 0\r\n" |
| 21002 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 21003 | // The client retries with credentials, and the request finally succeeds. |
| 21004 | mock_writes1.emplace_back( |
| 21005 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21006 | "Host: www.example.org:443\r\n" |
| 21007 | "Proxy-Connection: keep-alive\r\n" |
| 21008 | // Authenticate as proxyuser:proxypass. |
| 21009 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21010 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21011 | // The origin requests client certificates. |
| 21012 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21013 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 21014 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 21015 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21016 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 21017 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 21018 | |
| 21019 | // The client responds to the origin client certificate request on a new |
| 21020 | // connection. |
| 21021 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21022 | std::vector<MockWrite> mock_writes2; |
| 21023 | std::vector<MockRead> mock_reads2; |
| 21024 | mock_writes2.emplace_back( |
| 21025 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 21026 | "Host: www.example.org:443\r\n" |
| 21027 | "Proxy-Connection: keep-alive\r\n" |
| 21028 | // Authenticate as proxyuser:proxypass. |
| 21029 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 21030 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 21031 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 21032 | ssl_origin2.expected_send_client_cert = true; |
| 21033 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 21034 | // The client sends the origin HTTP request, which succeeds. |
| 21035 | mock_writes2.emplace_back( |
| 21036 | "GET / HTTP/1.1\r\n" |
| 21037 | "Host: www.example.org\r\n" |
| 21038 | "Connection: keep-alive\r\n\r\n"); |
| 21039 | mock_reads2.emplace_back( |
| 21040 | "HTTP/1.1 200 OK\r\n" |
| 21041 | "Content-Length: 0\r\n\r\n"); |
| 21042 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 21043 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 21046 | |
| 21047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21048 | |
| 21049 | // Start the request. |
| 21050 | TestCompletionCallback callback; |
| 21051 | auto trans = |
| 21052 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21053 | int rv = callback.GetResult( |
| 21054 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 21055 | |
| 21056 | // Handle the proxy HTTP auth challenge. |
| 21057 | ASSERT_THAT(rv, IsOk()); |
| 21058 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 21059 | EXPECT_TRUE( |
| 21060 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 21061 | rv = callback.GetResult(trans->RestartWithAuth( |
| 21062 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 21063 | callback.callback())); |
| 21064 | |
| 21065 | // Handle the origin client certificate challenge. |
| 21066 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21067 | SSLCertRequestInfo* cert_request_info = |
| 21068 | trans->GetResponseInfo()->cert_request_info.get(); |
| 21069 | ASSERT_TRUE(cert_request_info); |
| 21070 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 21071 | EXPECT_EQ(cert_request_info->host_and_port, |
| 21072 | cert_request_info_origin->host_and_port); |
| 21073 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 21074 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 21075 | callback.callback())); |
| 21076 | |
| 21077 | // The request completes. |
| 21078 | ASSERT_THAT(rv, IsOk()); |
| 21079 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame] | 21080 | } |
| 21081 | |
David Benjamin | 6e673a8 | 2019-04-30 22:52:58 | [diff] [blame] | 21082 | // Test that socket reuse works with client certificates. |
| 21083 | TEST_F(HttpNetworkTransactionTest, ClientCertSocketReuse) { |
| 21084 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 21085 | cert_request_info->host_and_port = HostPortPair("www.example.org", 443); |
| 21086 | |
| 21087 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 21088 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 21089 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 21090 | ASSERT_TRUE(identity); |
| 21091 | |
| 21092 | HttpRequestInfo request1; |
| 21093 | request1.method = "GET"; |
| 21094 | request1.url = GURL("https://www.example.org/a"); |
| 21095 | request1.traffic_annotation = |
| 21096 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21097 | |
| 21098 | HttpRequestInfo request2; |
| 21099 | request2.method = "GET"; |
| 21100 | request2.url = GURL("https://www.example.org/b"); |
| 21101 | request2.traffic_annotation = |
| 21102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21103 | |
| 21104 | // The first connection results in a client certificate request. |
| 21105 | StaticSocketDataProvider data1; |
| 21106 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21107 | SSLSocketDataProvider ssl1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 21108 | ssl1.cert_request_info = cert_request_info.get(); |
| 21109 | ssl1.expected_send_client_cert = false; |
| 21110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21111 | |
| 21112 | // The second connection succeeds and is usable for both requests. |
| 21113 | MockWrite mock_writes[] = { |
| 21114 | MockWrite("GET /a HTTP/1.1\r\n" |
| 21115 | "Host: www.example.org\r\n" |
| 21116 | "Connection: keep-alive\r\n\r\n"), |
| 21117 | MockWrite("GET /b HTTP/1.1\r\n" |
| 21118 | "Host: www.example.org\r\n" |
| 21119 | "Connection: keep-alive\r\n\r\n"), |
| 21120 | }; |
| 21121 | MockRead mock_reads[] = { |
| 21122 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21123 | "Content-Length: 0\r\n\r\n"), |
| 21124 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21125 | "Content-Length: 0\r\n\r\n"), |
| 21126 | }; |
| 21127 | StaticSocketDataProvider data2(mock_reads, mock_writes); |
| 21128 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21129 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 21130 | ssl2.expected_send_client_cert = true; |
| 21131 | ssl2.expected_client_cert = identity->certificate(); |
| 21132 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21133 | |
| 21134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21135 | |
| 21136 | // Start the first request. It succeeds after providing client certificates. |
| 21137 | TestCompletionCallback callback; |
| 21138 | auto trans = |
| 21139 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21140 | ASSERT_THAT(callback.GetResult(trans->Start(&request1, callback.callback(), |
| 21141 | NetLogWithSource())), |
| 21142 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 21143 | |
| 21144 | SSLCertRequestInfo* info = trans->GetResponseInfo()->cert_request_info.get(); |
| 21145 | ASSERT_TRUE(info); |
| 21146 | EXPECT_FALSE(info->is_proxy); |
| 21147 | EXPECT_EQ(info->host_and_port, cert_request_info->host_and_port); |
| 21148 | |
| 21149 | ASSERT_THAT(callback.GetResult(trans->RestartWithCertificate( |
| 21150 | identity->certificate(), identity->ssl_private_key(), |
| 21151 | callback.callback())), |
| 21152 | IsOk()); |
| 21153 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21154 | |
| 21155 | // Make the second request. It completes without requesting client |
| 21156 | // certificates. |
| 21157 | trans = |
| 21158 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21159 | ASSERT_THAT(callback.GetResult(trans->Start(&request2, callback.callback(), |
| 21160 | NetLogWithSource())), |
| 21161 | IsOk()); |
| 21162 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 21163 | } |
| 21164 | |
Matt Menke | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21165 | // Test for kPartitionConnectionsByNetworkIsolationKey. Runs 3 requests in |
| 21166 | // sequence with two different NetworkIsolationKeys, the first and last have the |
| 21167 | // same key, the second a different one. Checks that the requests are |
| 21168 | // partitioned across sockets as expected. |
| 21169 | TEST_F(HttpNetworkTransactionTest, NetworkIsolation) { |
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 | 166443c | 2019-05-24 18:45:59 | [diff] [blame] | 21174 | |
| 21175 | for (bool partition_connections : {false, true}) { |
| 21176 | SCOPED_TRACE(partition_connections); |
| 21177 | |
| 21178 | base::test::ScopedFeatureList feature_list; |
| 21179 | if (partition_connections) { |
| 21180 | feature_list.InitAndEnableFeature( |
| 21181 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21182 | } else { |
| 21183 | feature_list.InitAndDisableFeature( |
| 21184 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21185 | } |
| 21186 | |
| 21187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21188 | |
| 21189 | // Reads and writes for the unpartitioned case, where only one socket is |
| 21190 | // used. |
| 21191 | |
| 21192 | const MockWrite kUnpartitionedWrites[] = { |
| 21193 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21194 | "Host: foo.test\r\n" |
| 21195 | "Connection: keep-alive\r\n\r\n"), |
| 21196 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21197 | "Host: foo.test\r\n" |
| 21198 | "Connection: keep-alive\r\n\r\n"), |
| 21199 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21200 | "Host: foo.test\r\n" |
| 21201 | "Connection: keep-alive\r\n\r\n"), |
| 21202 | }; |
| 21203 | |
| 21204 | const MockRead kUnpartitionedReads[] = { |
| 21205 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21206 | "Connection: keep-alive\r\n" |
| 21207 | "Content-Length: 1\r\n\r\n" |
| 21208 | "1"), |
| 21209 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21210 | "Connection: keep-alive\r\n" |
| 21211 | "Content-Length: 1\r\n\r\n" |
| 21212 | "2"), |
| 21213 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21214 | "Connection: keep-alive\r\n" |
| 21215 | "Content-Length: 1\r\n\r\n" |
| 21216 | "3"), |
| 21217 | }; |
| 21218 | |
| 21219 | StaticSocketDataProvider unpartitioned_data(kUnpartitionedReads, |
| 21220 | kUnpartitionedWrites); |
| 21221 | |
| 21222 | // Reads and writes for the partitioned case, where two sockets are used. |
| 21223 | |
| 21224 | const MockWrite kPartitionedWrites1[] = { |
| 21225 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21226 | "Host: foo.test\r\n" |
| 21227 | "Connection: keep-alive\r\n\r\n"), |
| 21228 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21229 | "Host: foo.test\r\n" |
| 21230 | "Connection: keep-alive\r\n\r\n"), |
| 21231 | }; |
| 21232 | |
| 21233 | const MockRead kPartitionedReads1[] = { |
| 21234 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21235 | "Connection: keep-alive\r\n" |
| 21236 | "Content-Length: 1\r\n\r\n" |
| 21237 | "1"), |
| 21238 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21239 | "Connection: keep-alive\r\n" |
| 21240 | "Content-Length: 1\r\n\r\n" |
| 21241 | "3"), |
| 21242 | }; |
| 21243 | |
| 21244 | const MockWrite kPartitionedWrites2[] = { |
| 21245 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21246 | "Host: foo.test\r\n" |
| 21247 | "Connection: keep-alive\r\n\r\n"), |
| 21248 | }; |
| 21249 | |
| 21250 | const MockRead kPartitionedReads2[] = { |
| 21251 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21252 | "Connection: keep-alive\r\n" |
| 21253 | "Content-Length: 1\r\n\r\n" |
| 21254 | "2"), |
| 21255 | }; |
| 21256 | |
| 21257 | StaticSocketDataProvider partitioned_data1(kPartitionedReads1, |
| 21258 | kPartitionedWrites1); |
| 21259 | StaticSocketDataProvider partitioned_data2(kPartitionedReads2, |
| 21260 | kPartitionedWrites2); |
| 21261 | |
| 21262 | if (partition_connections) { |
| 21263 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 21264 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 21265 | } else { |
| 21266 | session_deps_.socket_factory->AddSocketDataProvider(&unpartitioned_data); |
| 21267 | } |
| 21268 | |
| 21269 | TestCompletionCallback callback; |
| 21270 | HttpRequestInfo request1; |
| 21271 | request1.method = "GET"; |
| 21272 | request1.url = GURL("http://foo.test/1"); |
| 21273 | request1.traffic_annotation = |
| 21274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21275 | request1.network_isolation_key = network_isolation_key1; |
| 21276 | auto trans1 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21277 | session.get()); |
| 21278 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21279 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21280 | std::string response_data1; |
| 21281 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21282 | EXPECT_EQ("1", response_data1); |
| 21283 | trans1.reset(); |
| 21284 | |
| 21285 | HttpRequestInfo request2; |
| 21286 | request2.method = "GET"; |
| 21287 | request2.url = GURL("http://foo.test/2"); |
| 21288 | request2.traffic_annotation = |
| 21289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21290 | request2.network_isolation_key = network_isolation_key2; |
| 21291 | auto trans2 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21292 | session.get()); |
| 21293 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21294 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21295 | std::string response_data2; |
| 21296 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21297 | EXPECT_EQ("2", response_data2); |
| 21298 | trans2.reset(); |
| 21299 | |
| 21300 | HttpRequestInfo request3; |
| 21301 | request3.method = "GET"; |
| 21302 | request3.url = GURL("http://foo.test/3"); |
| 21303 | request3.traffic_annotation = |
| 21304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21305 | request3.network_isolation_key = network_isolation_key1; |
| 21306 | auto trans3 = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 21307 | session.get()); |
| 21308 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21309 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21310 | std::string response_data3; |
| 21311 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21312 | EXPECT_EQ("3", response_data3); |
| 21313 | trans3.reset(); |
| 21314 | } |
| 21315 | } |
| 21316 | |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 21317 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationH2) { |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21318 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21319 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21320 | NetworkIsolationKey network_isolation_key1(kOrigin1, kOrigin1); |
| 21321 | NetworkIsolationKey network_isolation_key2(kOrigin2, kOrigin2); |
Matt Menke | ae58eeb | 2019-05-24 21:09:50 | [diff] [blame] | 21322 | |
| 21323 | // Whether to use an H2 proxy. When false, uses HTTPS H2 requests without a |
| 21324 | // proxy, when true, uses HTTP requests over an H2 proxy. It's unnecessary to |
| 21325 | // test tunneled HTTPS over an H2 proxy, since that path sets up H2 sessions |
| 21326 | // the same way as the HTTP over H2 proxy case. |
| 21327 | for (bool use_proxy : {false, true}) { |
| 21328 | SCOPED_TRACE(use_proxy); |
| 21329 | if (use_proxy) { |
| 21330 | session_deps_.proxy_resolution_service = |
| 21331 | ProxyResolutionService::CreateFixedFromPacResult( |
| 21332 | "HTTPS proxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21333 | } else { |
| 21334 | session_deps_.proxy_resolution_service = |
| 21335 | ProxyResolutionService::CreateDirect(); |
| 21336 | } |
| 21337 | const char* url1 = nullptr; |
| 21338 | const char* url2 = nullptr; |
| 21339 | const char* url3 = nullptr; |
| 21340 | if (use_proxy) { |
| 21341 | url1 = "http://foo.test/1"; |
| 21342 | url2 = "http://foo.test/2"; |
| 21343 | url3 = "http://foo.test/3"; |
| 21344 | } else { |
| 21345 | url1 = "https://foo.test/1"; |
| 21346 | url2 = "https://foo.test/2"; |
| 21347 | url3 = "https://foo.test/3"; |
| 21348 | } |
| 21349 | |
| 21350 | for (bool partition_connections : {false, true}) { |
| 21351 | SCOPED_TRACE(partition_connections); |
| 21352 | |
| 21353 | base::test::ScopedFeatureList feature_list; |
| 21354 | if (partition_connections) { |
| 21355 | feature_list.InitAndEnableFeature( |
| 21356 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21357 | } else { |
| 21358 | feature_list.InitAndDisableFeature( |
| 21359 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21360 | } |
| 21361 | |
| 21362 | std::unique_ptr<HttpNetworkSession> session( |
| 21363 | CreateSession(&session_deps_)); |
| 21364 | |
| 21365 | // Reads and writes for the unpartitioned case, where only one socket is |
| 21366 | // used. |
| 21367 | |
| 21368 | SpdyTestUtil spdy_util; |
| 21369 | spdy::SpdySerializedFrame unpartitioned_req1( |
| 21370 | spdy_util.ConstructSpdyGet(url1, 1, LOWEST)); |
| 21371 | spdy::SpdySerializedFrame unpartitioned_response1( |
| 21372 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21373 | spdy::SpdySerializedFrame unpartitioned_body1( |
| 21374 | spdy_util.ConstructSpdyDataFrame(1, "1", true)); |
| 21375 | spdy_util.UpdateWithStreamDestruction(1); |
| 21376 | |
| 21377 | spdy::SpdySerializedFrame unpartitioned_req2( |
| 21378 | spdy_util.ConstructSpdyGet(url2, 3, LOWEST)); |
| 21379 | spdy::SpdySerializedFrame unpartitioned_response2( |
| 21380 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 21381 | spdy::SpdySerializedFrame unpartitioned_body2( |
| 21382 | spdy_util.ConstructSpdyDataFrame(3, "2", true)); |
| 21383 | spdy_util.UpdateWithStreamDestruction(3); |
| 21384 | |
| 21385 | spdy::SpdySerializedFrame unpartitioned_req3( |
| 21386 | spdy_util.ConstructSpdyGet(url3, 5, LOWEST)); |
| 21387 | spdy::SpdySerializedFrame unpartitioned_response3( |
| 21388 | spdy_util.ConstructSpdyGetReply(nullptr, 0, 5)); |
| 21389 | spdy::SpdySerializedFrame unpartitioned_body3( |
| 21390 | spdy_util.ConstructSpdyDataFrame(5, "3", true)); |
| 21391 | |
| 21392 | const MockWrite kUnpartitionedWrites[] = { |
| 21393 | CreateMockWrite(unpartitioned_req1, 0), |
| 21394 | CreateMockWrite(unpartitioned_req2, 3), |
| 21395 | CreateMockWrite(unpartitioned_req3, 6), |
| 21396 | }; |
| 21397 | |
| 21398 | const MockRead kUnpartitionedReads[] = { |
| 21399 | CreateMockRead(unpartitioned_response1, 1), |
| 21400 | CreateMockRead(unpartitioned_body1, 2), |
| 21401 | CreateMockRead(unpartitioned_response2, 4), |
| 21402 | CreateMockRead(unpartitioned_body2, 5), |
| 21403 | CreateMockRead(unpartitioned_response3, 7), |
| 21404 | CreateMockRead(unpartitioned_body3, 8), |
| 21405 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 9), |
| 21406 | }; |
| 21407 | |
| 21408 | SequencedSocketData unpartitioned_data(kUnpartitionedReads, |
| 21409 | kUnpartitionedWrites); |
| 21410 | |
| 21411 | // Reads and writes for the partitioned case, where two sockets are used. |
| 21412 | |
| 21413 | SpdyTestUtil spdy_util2; |
| 21414 | spdy::SpdySerializedFrame partitioned_req1( |
| 21415 | spdy_util2.ConstructSpdyGet(url1, 1, LOWEST)); |
| 21416 | spdy::SpdySerializedFrame partitioned_response1( |
| 21417 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21418 | spdy::SpdySerializedFrame partitioned_body1( |
| 21419 | spdy_util2.ConstructSpdyDataFrame(1, "1", true)); |
| 21420 | spdy_util2.UpdateWithStreamDestruction(1); |
| 21421 | |
| 21422 | spdy::SpdySerializedFrame partitioned_req3( |
| 21423 | spdy_util2.ConstructSpdyGet(url3, 3, LOWEST)); |
| 21424 | spdy::SpdySerializedFrame partitioned_response3( |
| 21425 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 3)); |
| 21426 | spdy::SpdySerializedFrame partitioned_body3( |
| 21427 | spdy_util2.ConstructSpdyDataFrame(3, "3", true)); |
| 21428 | |
| 21429 | const MockWrite kPartitionedWrites1[] = { |
| 21430 | CreateMockWrite(partitioned_req1, 0), |
| 21431 | CreateMockWrite(partitioned_req3, 3), |
| 21432 | }; |
| 21433 | |
| 21434 | const MockRead kPartitionedReads1[] = { |
| 21435 | CreateMockRead(partitioned_response1, 1), |
| 21436 | CreateMockRead(partitioned_body1, 2), |
| 21437 | CreateMockRead(partitioned_response3, 4), |
| 21438 | CreateMockRead(partitioned_body3, 5), |
| 21439 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 21440 | }; |
| 21441 | |
| 21442 | SpdyTestUtil spdy_util3; |
| 21443 | spdy::SpdySerializedFrame partitioned_req2( |
| 21444 | spdy_util3.ConstructSpdyGet(url2, 1, LOWEST)); |
| 21445 | spdy::SpdySerializedFrame partitioned_response2( |
| 21446 | spdy_util3.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 21447 | spdy::SpdySerializedFrame partitioned_body2( |
| 21448 | spdy_util3.ConstructSpdyDataFrame(1, "2", true)); |
| 21449 | |
| 21450 | const MockWrite kPartitionedWrites2[] = { |
| 21451 | CreateMockWrite(partitioned_req2, 0), |
| 21452 | }; |
| 21453 | |
| 21454 | const MockRead kPartitionedReads2[] = { |
| 21455 | CreateMockRead(partitioned_response2, 1), |
| 21456 | CreateMockRead(partitioned_body2, 2), |
| 21457 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
| 21458 | }; |
| 21459 | |
| 21460 | SequencedSocketData partitioned_data1(kPartitionedReads1, |
| 21461 | kPartitionedWrites1); |
| 21462 | SequencedSocketData partitioned_data2(kPartitionedReads2, |
| 21463 | kPartitionedWrites2); |
| 21464 | |
| 21465 | // No need to segment SSLDataProviders by whether or not partitioning is |
| 21466 | // enabled. |
| 21467 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 21468 | ssl_data1.next_proto = kProtoHTTP2; |
| 21469 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 21470 | ssl_data2.next_proto = kProtoHTTP2; |
| 21471 | |
| 21472 | if (partition_connections) { |
| 21473 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data1); |
| 21474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21475 | session_deps_.socket_factory->AddSocketDataProvider(&partitioned_data2); |
| 21476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 21477 | } else { |
| 21478 | session_deps_.socket_factory->AddSocketDataProvider( |
| 21479 | &unpartitioned_data); |
| 21480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21481 | } |
| 21482 | |
| 21483 | TestCompletionCallback callback; |
| 21484 | HttpRequestInfo request1; |
| 21485 | request1.method = "GET"; |
| 21486 | request1.url = GURL(url1); |
| 21487 | request1.traffic_annotation = |
| 21488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21489 | request1.network_isolation_key = network_isolation_key1; |
| 21490 | auto trans1 = |
| 21491 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21492 | int rv = |
| 21493 | trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21494 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21495 | std::string response_data1; |
| 21496 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21497 | EXPECT_EQ("1", response_data1); |
| 21498 | trans1.reset(); |
| 21499 | |
| 21500 | HttpRequestInfo request2; |
| 21501 | request2.method = "GET"; |
| 21502 | request2.url = GURL(url2); |
| 21503 | request2.traffic_annotation = |
| 21504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21505 | request2.network_isolation_key = network_isolation_key2; |
| 21506 | auto trans2 = |
| 21507 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21508 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21509 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21510 | std::string response_data2; |
| 21511 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21512 | EXPECT_EQ("2", response_data2); |
| 21513 | trans2.reset(); |
| 21514 | |
| 21515 | HttpRequestInfo request3; |
| 21516 | request3.method = "GET"; |
| 21517 | request3.url = GURL(url3); |
| 21518 | request3.traffic_annotation = |
| 21519 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21520 | request3.network_isolation_key = network_isolation_key1; |
| 21521 | auto trans3 = |
| 21522 | std::make_unique<HttpNetworkTransaction>(LOWEST, session.get()); |
| 21523 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21524 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21525 | std::string response_data3; |
| 21526 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21527 | EXPECT_EQ("3", response_data3); |
| 21528 | trans3.reset(); |
| 21529 | } |
| 21530 | } |
| 21531 | } |
| 21532 | |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 21533 | // Preconnect two sockets with different NetworkIsolationKeys when |
| 21534 | // features::kPartitionConnectionsByNetworkIsolationKey is enabled. Then issue a |
| 21535 | // request and make sure the correct socket is used. Loops three times, |
| 21536 | // expecting to use the first preconnect, second preconnect, and neither. |
| 21537 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationPreconnect) { |
| 21538 | base::test::ScopedFeatureList feature_list; |
| 21539 | feature_list.InitAndEnableFeature( |
| 21540 | features::kPartitionConnectionsByNetworkIsolationKey); |
| 21541 | |
| 21542 | enum class TestCase { |
| 21543 | kUseFirstPreconnect, |
| 21544 | kUseSecondPreconnect, |
| 21545 | kDontUsePreconnect, |
| 21546 | }; |
| 21547 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21548 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21549 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21550 | const auto kOrigin3 = url::Origin::Create(GURL("http://origin3/")); |
| 21551 | NetworkIsolationKey preconnect1_isolation_key(kOrigin1, kOrigin1); |
| 21552 | NetworkIsolationKey preconnect2_isolation_key(kOrigin2, kOrigin2); |
| 21553 | NetworkIsolationKey not_preconnected_isolation_key(kOrigin3, kOrigin3); |
Matt Menke | 7281f87 | 2019-06-25 19:29:25 | [diff] [blame] | 21554 | |
| 21555 | // Test that only preconnects with |
| 21556 | for (TestCase test_case : |
| 21557 | {TestCase::kUseFirstPreconnect, TestCase::kUseSecondPreconnect, |
| 21558 | TestCase::kDontUsePreconnect}) { |
| 21559 | SpdySessionDependencies session_deps; |
| 21560 | // Make DNS lookups completely synchronously, so preconnects complete |
| 21561 | // immediately. |
| 21562 | session_deps.host_resolver->set_synchronous_mode(true); |
| 21563 | |
| 21564 | const MockWrite kMockWrites[] = { |
| 21565 | MockWrite(ASYNC, 0, |
| 21566 | "GET / HTTP/1.1\r\n" |
| 21567 | "Host: www.foo.com\r\n" |
| 21568 | "Connection: keep-alive\r\n\r\n"), |
| 21569 | }; |
| 21570 | |
| 21571 | const MockRead kMockReads[] = { |
| 21572 | MockRead(ASYNC, 1, |
| 21573 | "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n" |
| 21574 | "hello"), |
| 21575 | }; |
| 21576 | |
| 21577 | // Used for the socket that will actually be used, which may or may not be |
| 21578 | // one of the preconnects |
| 21579 | SequencedSocketData used_socket_data(MockConnect(SYNCHRONOUS, OK), |
| 21580 | kMockReads, kMockWrites); |
| 21581 | |
| 21582 | // Used for the preconnects that won't actually be used. |
| 21583 | SequencedSocketData preconnect1_data(MockConnect(SYNCHRONOUS, OK), |
| 21584 | base::span<const MockRead>(), |
| 21585 | base::span<const MockWrite>()); |
| 21586 | SequencedSocketData preconnect2_data(MockConnect(SYNCHRONOUS, OK), |
| 21587 | base::span<const MockRead>(), |
| 21588 | base::span<const MockWrite>()); |
| 21589 | |
| 21590 | NetworkIsolationKey network_isolation_key_for_request; |
| 21591 | |
| 21592 | switch (test_case) { |
| 21593 | case TestCase::kUseFirstPreconnect: |
| 21594 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21595 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 21596 | network_isolation_key_for_request = preconnect1_isolation_key; |
| 21597 | break; |
| 21598 | case TestCase::kUseSecondPreconnect: |
| 21599 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 21600 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21601 | network_isolation_key_for_request = preconnect2_isolation_key; |
| 21602 | break; |
| 21603 | case TestCase::kDontUsePreconnect: |
| 21604 | session_deps.socket_factory->AddSocketDataProvider(&preconnect1_data); |
| 21605 | session_deps.socket_factory->AddSocketDataProvider(&preconnect2_data); |
| 21606 | session_deps.socket_factory->AddSocketDataProvider(&used_socket_data); |
| 21607 | network_isolation_key_for_request = not_preconnected_isolation_key; |
| 21608 | break; |
| 21609 | } |
| 21610 | |
| 21611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 21612 | |
| 21613 | // Preconnect sockets. |
| 21614 | HttpRequestInfo request; |
| 21615 | request.method = "GET"; |
| 21616 | request.url = GURL("http://www.foo.com/"); |
| 21617 | request.traffic_annotation = |
| 21618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21619 | |
| 21620 | request.network_isolation_key = preconnect1_isolation_key; |
| 21621 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 21622 | |
| 21623 | request.network_isolation_key = preconnect2_isolation_key; |
| 21624 | session->http_stream_factory()->PreconnectStreams(1, request); |
| 21625 | |
| 21626 | request.network_isolation_key = network_isolation_key_for_request; |
| 21627 | |
| 21628 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21629 | |
| 21630 | // Make the request. |
| 21631 | TestCompletionCallback callback; |
| 21632 | |
| 21633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 21634 | |
| 21635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 21636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 21637 | |
| 21638 | rv = callback.WaitForResult(); |
| 21639 | EXPECT_THAT(rv, IsOk()); |
| 21640 | |
| 21641 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 21642 | ASSERT_TRUE(response); |
| 21643 | ASSERT_TRUE(response->headers); |
| 21644 | EXPECT_EQ(200, response->headers->response_code()); |
| 21645 | |
| 21646 | std::string response_data; |
| 21647 | rv = ReadTransaction(&trans, &response_data); |
| 21648 | EXPECT_THAT(rv, IsOk()); |
| 21649 | EXPECT_EQ("hello", response_data); |
| 21650 | |
| 21651 | if (test_case != TestCase::kDontUsePreconnect) { |
| 21652 | EXPECT_EQ(2, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21653 | } else { |
| 21654 | EXPECT_EQ(3, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 21655 | } |
| 21656 | } |
| 21657 | } |
| 21658 | |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21659 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 21660 | // cache is isolated. |
| 21661 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSL) { |
| 21662 | base::test::ScopedFeatureList feature_list; |
| 21663 | feature_list.InitWithFeatures( |
| 21664 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 21665 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 21666 | {}); |
| 21667 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21668 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21669 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21670 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 21671 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21673 | |
| 21674 | // The server always sends Connection: close, so each request goes over a |
| 21675 | // distinct socket. |
| 21676 | |
| 21677 | const MockWrite kWrites1[] = { |
| 21678 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21679 | "Host: foo.test\r\n" |
| 21680 | "Connection: keep-alive\r\n\r\n")}; |
| 21681 | |
| 21682 | const MockRead kReads1[] = { |
| 21683 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21684 | "Connection: close\r\n" |
| 21685 | "Content-Length: 1\r\n\r\n" |
| 21686 | "1")}; |
| 21687 | |
| 21688 | const MockWrite kWrites2[] = { |
| 21689 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21690 | "Host: foo.test\r\n" |
| 21691 | "Connection: keep-alive\r\n\r\n")}; |
| 21692 | |
| 21693 | const MockRead kReads2[] = { |
| 21694 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21695 | "Connection: close\r\n" |
| 21696 | "Content-Length: 1\r\n\r\n" |
| 21697 | "2")}; |
| 21698 | |
| 21699 | const MockWrite kWrites3[] = { |
| 21700 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21701 | "Host: foo.test\r\n" |
| 21702 | "Connection: keep-alive\r\n\r\n")}; |
| 21703 | |
| 21704 | const MockRead kReads3[] = { |
| 21705 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21706 | "Connection: close\r\n" |
| 21707 | "Content-Length: 1\r\n\r\n" |
| 21708 | "3")}; |
| 21709 | |
| 21710 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21711 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21712 | StaticSocketDataProvider data3(kReads3, kWrites3); |
| 21713 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21714 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21715 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 21716 | |
| 21717 | SSLSocketDataProvider ssl_data1(ASYNC, OK); |
| 21718 | ssl_data1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21719 | ssl_data1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21720 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
| 21721 | ssl_data2.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21722 | ssl_data2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 21723 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
| 21724 | ssl_data3.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21725 | ssl_data3.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 21727 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
| 21728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
| 21729 | |
| 21730 | TestCompletionCallback callback; |
| 21731 | HttpRequestInfo request1; |
| 21732 | request1.method = "GET"; |
| 21733 | request1.url = GURL("https://foo.test/1"); |
| 21734 | request1.traffic_annotation = |
| 21735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21736 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 21737 | auto trans1 = |
| 21738 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21739 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21740 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21741 | std::string response_data1; |
| 21742 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21743 | EXPECT_EQ("1", response_data1); |
| 21744 | trans1.reset(); |
| 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 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 21752 | auto trans2 = |
| 21753 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21754 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21755 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21756 | std::string response_data2; |
| 21757 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21758 | EXPECT_EQ("2", response_data2); |
| 21759 | trans2.reset(); |
| 21760 | |
| 21761 | HttpRequestInfo request3; |
| 21762 | request3.method = "GET"; |
| 21763 | request3.url = GURL("https://foo.test/3"); |
| 21764 | request3.traffic_annotation = |
| 21765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21766 | request3.network_isolation_key = kNetworkIsolationKey1; |
| 21767 | auto trans3 = |
| 21768 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21769 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21770 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21771 | std::string response_data3; |
| 21772 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21773 | EXPECT_EQ("3", response_data3); |
| 21774 | trans3.reset(); |
| 21775 | } |
| 21776 | |
| 21777 | // Test that the NetworkIsolationKey is passed down to SSLConfig so the session |
| 21778 | // cache is isolated, for both origins and proxies. |
| 21779 | TEST_F(HttpNetworkTransactionTest, NetworkIsolationSSLProxy) { |
| 21780 | base::test::ScopedFeatureList feature_list; |
| 21781 | feature_list.InitWithFeatures( |
| 21782 | {features::kPartitionConnectionsByNetworkIsolationKey, |
| 21783 | features::kPartitionSSLSessionsByNetworkIsolationKey}, |
| 21784 | {}); |
| 21785 | |
| 21786 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 21787 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21788 | |
Shivani Sharma | 8ae506c | 2019-07-21 21:08:27 | [diff] [blame] | 21789 | const auto kOrigin1 = url::Origin::Create(GURL("http://origin1/")); |
| 21790 | const auto kOrigin2 = url::Origin::Create(GURL("http://origin2/")); |
| 21791 | const NetworkIsolationKey kNetworkIsolationKey1(kOrigin1, kOrigin1); |
| 21792 | const NetworkIsolationKey kNetworkIsolationKey2(kOrigin2, kOrigin2); |
David Benjamin | 6f2da65 | 2019-06-26 23:36:35 | [diff] [blame] | 21793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 21794 | |
| 21795 | // Make both a tunneled and non-tunneled request. |
| 21796 | HttpRequestInfo request1; |
| 21797 | request1.method = "GET"; |
| 21798 | request1.url = GURL("https://foo.test/1"); |
| 21799 | request1.traffic_annotation = |
| 21800 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21801 | request1.network_isolation_key = kNetworkIsolationKey1; |
| 21802 | |
| 21803 | HttpRequestInfo request2; |
| 21804 | request2.method = "GET"; |
| 21805 | request2.url = GURL("http://foo.test/2"); |
| 21806 | request2.traffic_annotation = |
| 21807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21808 | request2.network_isolation_key = kNetworkIsolationKey2; |
| 21809 | |
| 21810 | const MockWrite kWrites1[] = { |
| 21811 | MockWrite("CONNECT foo.test:443 HTTP/1.1\r\n" |
| 21812 | "Host: foo.test:443\r\n" |
| 21813 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 21814 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21815 | "Host: foo.test\r\n" |
| 21816 | "Connection: keep-alive\r\n\r\n")}; |
| 21817 | |
| 21818 | const MockRead kReads1[] = { |
| 21819 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 21820 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21821 | "Connection: close\r\n" |
| 21822 | "Content-Length: 1\r\n\r\n" |
| 21823 | "1")}; |
| 21824 | |
| 21825 | const MockWrite kWrites2[] = { |
| 21826 | MockWrite("GET http://foo.test/2 HTTP/1.1\r\n" |
| 21827 | "Host: foo.test\r\n" |
| 21828 | "Proxy-Connection: keep-alive\r\n\r\n")}; |
| 21829 | |
| 21830 | const MockRead kReads2[] = { |
| 21831 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21832 | "Connection: close\r\n" |
| 21833 | "Content-Length: 1\r\n\r\n" |
| 21834 | "2")}; |
| 21835 | |
| 21836 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21837 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21838 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21839 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21840 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21841 | |
| 21842 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 21843 | ssl_proxy1.expected_host_and_port = HostPortPair("myproxy", 70); |
| 21844 | ssl_proxy1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21845 | SSLSocketDataProvider ssl_origin1(ASYNC, OK); |
| 21846 | ssl_origin1.expected_host_and_port = HostPortPair("foo.test", 443); |
| 21847 | ssl_origin1.expected_network_isolation_key = kNetworkIsolationKey1; |
| 21848 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 21849 | ssl_proxy2.expected_host_and_port = HostPortPair("myproxy", 70); |
| 21850 | ssl_proxy2.expected_network_isolation_key = kNetworkIsolationKey2; |
| 21851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 21852 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 21853 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 21854 | |
| 21855 | TestCompletionCallback callback; |
| 21856 | auto trans1 = |
| 21857 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21858 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21859 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21860 | std::string response_data1; |
| 21861 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21862 | EXPECT_EQ("1", response_data1); |
| 21863 | trans1.reset(); |
| 21864 | |
| 21865 | auto trans2 = |
| 21866 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21867 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21868 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21869 | std::string response_data2; |
| 21870 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21871 | EXPECT_EQ("2", response_data2); |
| 21872 | trans2.reset(); |
| 21873 | } |
| 21874 | |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21875 | // Test that SSLConfig changes from SSLConfigService are picked up even when |
| 21876 | // there are live sockets. |
| 21877 | TEST_F(HttpNetworkTransactionTest, SSLConfigChanged) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21878 | SSLContextConfig ssl_context_config; |
| 21879 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21880 | auto ssl_config_service = |
| 21881 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21882 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 21883 | |
| 21884 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 21885 | |
| 21886 | // Make three requests. Between the second and third, the SSL config will |
| 21887 | // change. |
| 21888 | HttpRequestInfo request1; |
| 21889 | request1.method = "GET"; |
| 21890 | request1.url = GURL("https://foo.test/1"); |
| 21891 | request1.traffic_annotation = |
| 21892 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21893 | |
| 21894 | HttpRequestInfo request2; |
| 21895 | request2.method = "GET"; |
| 21896 | request2.url = GURL("https://foo.test/2"); |
| 21897 | request2.traffic_annotation = |
| 21898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21899 | |
| 21900 | HttpRequestInfo request3; |
| 21901 | request3.method = "GET"; |
| 21902 | request3.url = GURL("https://foo.test/3"); |
| 21903 | request3.traffic_annotation = |
| 21904 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21905 | |
| 21906 | const MockWrite kWrites1[] = { |
| 21907 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 21908 | "Host: foo.test\r\n" |
| 21909 | "Connection: keep-alive\r\n\r\n"), |
| 21910 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 21911 | "Host: foo.test\r\n" |
| 21912 | "Connection: keep-alive\r\n\r\n"), |
| 21913 | }; |
| 21914 | |
| 21915 | const MockRead kReads1[] = { |
| 21916 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21917 | "Connection: keep-alive\r\n" |
| 21918 | "Content-Length: 1\r\n\r\n" |
| 21919 | "1"), |
| 21920 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21921 | "Connection: keep-alive\r\n" |
| 21922 | "Content-Length: 1\r\n\r\n" |
| 21923 | "2"), |
| 21924 | }; |
| 21925 | |
| 21926 | // The third request goes on a different socket because the SSL config has |
| 21927 | // changed. |
| 21928 | const MockWrite kWrites2[] = { |
| 21929 | MockWrite("GET /3 HTTP/1.1\r\n" |
| 21930 | "Host: foo.test\r\n" |
| 21931 | "Connection: keep-alive\r\n\r\n")}; |
| 21932 | |
| 21933 | const MockRead kReads2[] = { |
| 21934 | MockRead("HTTP/1.1 200 OK\r\n" |
| 21935 | "Connection: keep-alive\r\n" |
| 21936 | "Content-Length: 1\r\n\r\n" |
| 21937 | "3")}; |
| 21938 | |
| 21939 | StaticSocketDataProvider data1(kReads1, kWrites1); |
| 21940 | StaticSocketDataProvider data2(kReads2, kWrites2); |
| 21941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 21942 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 21943 | |
| 21944 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 21945 | ssl1.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21946 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 21947 | ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 21948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 21949 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 21950 | |
| 21951 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 21952 | |
| 21953 | TestCompletionCallback callback; |
| 21954 | auto trans1 = |
| 21955 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21956 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 21957 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21958 | std::string response_data1; |
| 21959 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
| 21960 | EXPECT_EQ("1", response_data1); |
| 21961 | trans1.reset(); |
| 21962 | |
| 21963 | auto trans2 = |
| 21964 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21965 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
| 21966 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21967 | std::string response_data2; |
| 21968 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
| 21969 | EXPECT_EQ("2", response_data2); |
| 21970 | trans2.reset(); |
| 21971 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21972 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 21973 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21974 | |
| 21975 | auto trans3 = |
| 21976 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 21977 | rv = trans3->Start(&request3, callback.callback(), NetLogWithSource()); |
| 21978 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 21979 | std::string response_data3; |
| 21980 | EXPECT_THAT(ReadTransaction(trans3.get(), &response_data3), IsOk()); |
| 21981 | EXPECT_EQ("3", response_data3); |
| 21982 | trans3.reset(); |
| 21983 | } |
| 21984 | |
| 21985 | TEST_F(HttpNetworkTransactionTest, SSLConfigChangedPendingConnect) { |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 21986 | SSLContextConfig ssl_context_config; |
| 21987 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 21988 | auto ssl_config_service = |
| 21989 | std::make_unique<TestSSLConfigService>(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 21990 | TestSSLConfigService* ssl_config_service_raw = ssl_config_service.get(); |
| 21991 | |
| 21992 | session_deps_.ssl_config_service = std::move(ssl_config_service); |
| 21993 | |
| 21994 | HttpRequestInfo request; |
| 21995 | request.method = "GET"; |
| 21996 | request.url = GURL("https://foo.test/1"); |
| 21997 | request.traffic_annotation = |
| 21998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 21999 | |
| 22000 | // Make a socket which never connects. |
| 22001 | StaticSocketDataProvider data({}, {}); |
| 22002 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 22003 | SSLSocketDataProvider ssl_data(SYNCHRONOUS, ERR_IO_PENDING); |
| 22004 | ssl_data.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 22005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
| 22006 | |
| 22007 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22008 | |
| 22009 | TestCompletionCallback callback; |
| 22010 | auto trans = |
| 22011 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22012 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 22013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22014 | |
David Benjamin | 151ec6b | 2019-08-02 19:38:52 | [diff] [blame] | 22015 | ssl_context_config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 22016 | ssl_config_service_raw->UpdateSSLConfigAndNotify(ssl_context_config); |
David Benjamin | ef2f2a5a | 2019-07-16 19:21:31 | [diff] [blame] | 22017 | |
| 22018 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NETWORK_CHANGED)); |
| 22019 | } |
| 22020 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 22021 | // Test that HttpNetworkTransaction correctly handles existing sockets when the |
| 22022 | // server requests a client certificate post-handshake (via a TLS |
| 22023 | // renegotiation). This is a regression test for https://crbug.com/829184. |
| 22024 | TEST_F(HttpNetworkTransactionTest, PostHandshakeClientCertWithSockets) { |
| 22025 | const MutableNetworkTrafficAnnotationTag kTrafficAnnotation( |
| 22026 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 22027 | |
| 22028 | auto cert_request_info = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 22029 | cert_request_info->host_and_port = HostPortPair("foo.test", 443); |
| 22030 | |
| 22031 | std::unique_ptr<FakeClientCertIdentity> identity = |
| 22032 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 22033 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 22034 | ASSERT_TRUE(identity); |
| 22035 | |
| 22036 | // This test will make several requests so that, when the client certificate |
| 22037 | // request comes in, we have a socket in use, an idle socket, and a socket for |
| 22038 | // an unrelated host. |
| 22039 | // |
| 22040 | // First, two long-lived requests which do not complete until after the client |
| 22041 | // certificate request. This arranges for sockets to be in use during the |
| 22042 | // request. They should not be interrupted. |
| 22043 | HttpRequestInfo request_long_lived; |
| 22044 | request_long_lived.method = "GET"; |
| 22045 | request_long_lived.url = GURL("https://foo.test/long-lived"); |
| 22046 | request_long_lived.traffic_annotation = kTrafficAnnotation; |
| 22047 | |
| 22048 | HttpRequestInfo request_long_lived_bar; |
| 22049 | request_long_lived_bar.method = "GET"; |
| 22050 | request_long_lived_bar.url = GURL("https://bar.test/long-lived"); |
| 22051 | request_long_lived_bar.traffic_annotation = kTrafficAnnotation; |
| 22052 | |
| 22053 | // Next, make a request that needs client certificates. |
| 22054 | HttpRequestInfo request_auth; |
| 22055 | request_auth.method = "GET"; |
| 22056 | request_auth.url = GURL("https://foo.test/auth"); |
| 22057 | request_auth.traffic_annotation = kTrafficAnnotation; |
| 22058 | |
| 22059 | // Before responding to the challenge, make a request to an unauthenticated |
| 22060 | // endpoint. This will result in an idle socket when the client certificate |
| 22061 | // challenge is resolved. |
| 22062 | HttpRequestInfo request_unauth; |
| 22063 | request_unauth.method = "GET"; |
| 22064 | request_unauth.url = GURL("https://foo.test/unauth"); |
| 22065 | request_unauth.traffic_annotation = kTrafficAnnotation; |
| 22066 | |
| 22067 | // After all the preceding requests complete, end with two additional requests |
| 22068 | // to ensure pre-authentication foo.test sockets are not used and bar.test |
| 22069 | // sockets are unaffected. |
| 22070 | HttpRequestInfo request_post_auth; |
| 22071 | request_post_auth.method = "GET"; |
| 22072 | request_post_auth.url = GURL("https://foo.test/post-auth"); |
| 22073 | request_post_auth.traffic_annotation = kTrafficAnnotation; |
| 22074 | |
| 22075 | HttpRequestInfo request_post_auth_bar; |
| 22076 | request_post_auth_bar.method = "GET"; |
| 22077 | request_post_auth_bar.url = GURL("https://bar.test/post-auth"); |
| 22078 | request_post_auth_bar.traffic_annotation = kTrafficAnnotation; |
| 22079 | |
| 22080 | // The sockets for /long-lived and /unauth complete their request but are |
| 22081 | // not allocated for /post-auth or /retry because SSL state has since changed. |
| 22082 | const MockWrite kLongLivedWrites[] = { |
| 22083 | MockWrite(ASYNC, 0, |
| 22084 | "GET /long-lived HTTP/1.1\r\n" |
| 22085 | "Host: foo.test\r\n" |
| 22086 | "Connection: keep-alive\r\n\r\n"), |
| 22087 | }; |
| 22088 | const MockRead kLongLivedReads[] = { |
| 22089 | // Pause so /long-lived completes after the client presents client |
| 22090 | // certificates. |
| 22091 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 22092 | MockRead(ASYNC, 2, |
| 22093 | "HTTP/1.1 200 OK\r\n" |
| 22094 | "Connection: keep-alive\r\n" |
| 22095 | "Content-Length: 10\r\n\r\n" |
| 22096 | "long-lived"), |
| 22097 | }; |
| 22098 | SequencedSocketData data_long_lived(kLongLivedReads, kLongLivedWrites); |
| 22099 | SSLSocketDataProvider ssl_long_lived(ASYNC, OK); |
| 22100 | session_deps_.socket_factory->AddSocketDataProvider(&data_long_lived); |
| 22101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_long_lived); |
| 22102 | |
| 22103 | // Requests for bar.test should be unaffected by foo.test and get allocated |
| 22104 | // a single socket. |
| 22105 | const MockWrite kBarWrites[] = { |
| 22106 | MockWrite(ASYNC, 0, |
| 22107 | "GET /long-lived HTTP/1.1\r\n" |
| 22108 | "Host: bar.test\r\n" |
| 22109 | "Connection: keep-alive\r\n\r\n"), |
| 22110 | MockWrite(ASYNC, 3, |
| 22111 | "GET /post-auth HTTP/1.1\r\n" |
| 22112 | "Host: bar.test\r\n" |
| 22113 | "Connection: keep-alive\r\n\r\n"), |
| 22114 | }; |
| 22115 | const MockRead kBarReads[] = { |
| 22116 | // Pause on /long-lived so it completes after foo.test's authentication. |
| 22117 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 22118 | MockRead(ASYNC, 2, |
| 22119 | "HTTP/1.1 200 OK\r\n" |
| 22120 | "Connection: keep-alive\r\n" |
| 22121 | "Content-Length: 10\r\n\r\n" |
| 22122 | "long-lived"), |
| 22123 | MockRead(ASYNC, 4, |
| 22124 | "HTTP/1.1 200 OK\r\n" |
| 22125 | "Connection: keep-alive\r\n" |
| 22126 | "Content-Length: 9\r\n\r\n" |
| 22127 | "post-auth"), |
| 22128 | }; |
| 22129 | SequencedSocketData data_bar(kBarReads, kBarWrites); |
| 22130 | SSLSocketDataProvider ssl_bar(ASYNC, OK); |
| 22131 | session_deps_.socket_factory->AddSocketDataProvider(&data_bar); |
| 22132 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bar); |
| 22133 | |
| 22134 | // Requesting /auth results in a post-handshake client certificate challenge. |
| 22135 | const MockWrite kAuthWrites[] = { |
| 22136 | MockWrite(ASYNC, 0, |
| 22137 | "GET /auth HTTP/1.1\r\n" |
| 22138 | "Host: foo.test\r\n" |
| 22139 | "Connection: keep-alive\r\n\r\n"), |
| 22140 | }; |
| 22141 | const MockRead kAuthReads[] = { |
| 22142 | MockRead(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED, 1), |
| 22143 | }; |
| 22144 | SequencedSocketData data_auth(kAuthReads, kAuthWrites); |
| 22145 | SSLSocketDataProvider ssl_auth(ASYNC, OK); |
| 22146 | ssl_auth.cert_request_info = cert_request_info.get(); |
| 22147 | session_deps_.socket_factory->AddSocketDataProvider(&data_auth); |
| 22148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_auth); |
| 22149 | |
| 22150 | // Requesting /unauth completes. |
| 22151 | const MockWrite kUnauthWrites[] = { |
| 22152 | MockWrite(ASYNC, 0, |
| 22153 | "GET /unauth HTTP/1.1\r\n" |
| 22154 | "Host: foo.test\r\n" |
| 22155 | "Connection: keep-alive\r\n\r\n"), |
| 22156 | }; |
| 22157 | const MockRead kUnauthReads[] = { |
| 22158 | MockRead(ASYNC, 1, |
| 22159 | "HTTP/1.1 200 OK\r\n" |
| 22160 | "Connection: keep-alive\r\n" |
| 22161 | "Content-Length: 6\r\n\r\n" |
| 22162 | "unauth"), |
| 22163 | }; |
| 22164 | SequencedSocketData data_unauth(kUnauthReads, kUnauthWrites); |
| 22165 | SSLSocketDataProvider ssl_unauth(ASYNC, OK); |
| 22166 | session_deps_.socket_factory->AddSocketDataProvider(&data_unauth); |
| 22167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_unauth); |
| 22168 | |
| 22169 | // When the client certificate is selected, /auth is retried on a new |
| 22170 | // connection. In particular, it should not be retried on |data_unauth|, |
| 22171 | // which would not honor the new client certificate configuration. |
| 22172 | const MockWrite kRetryWrites[] = { |
| 22173 | MockWrite(ASYNC, 0, |
| 22174 | "GET /auth HTTP/1.1\r\n" |
| 22175 | "Host: foo.test\r\n" |
| 22176 | "Connection: keep-alive\r\n\r\n"), |
| 22177 | }; |
| 22178 | const MockRead kRetryReads[] = { |
| 22179 | MockRead(ASYNC, 1, |
| 22180 | "HTTP/1.1 200 OK\r\n" |
| 22181 | // Close the connection so we test that /post-auth is not |
| 22182 | // allocated to |data_unauth| or |data_long_lived|. |
| 22183 | "Connection: close\r\n" |
| 22184 | "Content-Length: 4\r\n\r\n" |
| 22185 | "auth"), |
| 22186 | }; |
| 22187 | SequencedSocketData data_retry(kRetryReads, kRetryWrites); |
| 22188 | SSLSocketDataProvider ssl_retry(ASYNC, OK); |
| 22189 | ssl_retry.expected_send_client_cert = true; |
| 22190 | ssl_retry.expected_client_cert = identity->certificate(); |
| 22191 | session_deps_.socket_factory->AddSocketDataProvider(&data_retry); |
| 22192 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_retry); |
| 22193 | |
| 22194 | // /post-auth gets its own socket. |
| 22195 | const MockWrite kPostAuthWrites[] = { |
| 22196 | MockWrite(ASYNC, 0, |
| 22197 | "GET /post-auth HTTP/1.1\r\n" |
| 22198 | "Host: foo.test\r\n" |
| 22199 | "Connection: keep-alive\r\n\r\n"), |
| 22200 | }; |
| 22201 | const MockRead kPostAuthReads[] = { |
| 22202 | MockRead(ASYNC, 1, |
| 22203 | "HTTP/1.1 200 OK\r\n" |
| 22204 | "Connection: keep-alive\r\n" |
| 22205 | "Content-Length: 9\r\n\r\n" |
| 22206 | "post-auth"), |
| 22207 | }; |
| 22208 | SequencedSocketData data_post_auth(kPostAuthReads, kPostAuthWrites); |
| 22209 | SSLSocketDataProvider ssl_post_auth(ASYNC, OK); |
| 22210 | ssl_post_auth.expected_send_client_cert = true; |
| 22211 | ssl_post_auth.expected_client_cert = identity->certificate(); |
| 22212 | session_deps_.socket_factory->AddSocketDataProvider(&data_post_auth); |
| 22213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_post_auth); |
| 22214 | |
| 22215 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 22216 | |
| 22217 | // Start the two long-lived requests. |
| 22218 | TestCompletionCallback callback_long_lived; |
| 22219 | auto trans_long_lived = |
| 22220 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22221 | int rv = trans_long_lived->Start( |
| 22222 | &request_long_lived, callback_long_lived.callback(), NetLogWithSource()); |
| 22223 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22224 | data_long_lived.RunUntilPaused(); |
| 22225 | |
| 22226 | TestCompletionCallback callback_long_lived_bar; |
| 22227 | auto trans_long_lived_bar = |
| 22228 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22229 | rv = trans_long_lived_bar->Start(&request_long_lived_bar, |
| 22230 | callback_long_lived_bar.callback(), |
| 22231 | NetLogWithSource()); |
| 22232 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 22233 | data_bar.RunUntilPaused(); |
| 22234 | |
| 22235 | // Request /auth. This gives a client certificate challenge. |
| 22236 | TestCompletionCallback callback_auth; |
| 22237 | auto trans_auth = |
| 22238 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22239 | rv = trans_auth->Start(&request_auth, callback_auth.callback(), |
| 22240 | NetLogWithSource()); |
| 22241 | EXPECT_THAT(callback_auth.GetResult(rv), |
| 22242 | IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 22243 | |
| 22244 | // Make an unauthenticated request. This completes. |
| 22245 | TestCompletionCallback callback_unauth; |
| 22246 | auto trans_unauth = |
| 22247 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22248 | rv = trans_unauth->Start(&request_unauth, callback_unauth.callback(), |
| 22249 | NetLogWithSource()); |
| 22250 | EXPECT_THAT(callback_unauth.GetResult(rv), IsOk()); |
| 22251 | std::string response_unauth; |
| 22252 | EXPECT_THAT(ReadTransaction(trans_unauth.get(), &response_unauth), IsOk()); |
| 22253 | EXPECT_EQ("unauth", response_unauth); |
| 22254 | trans_unauth.reset(); |
| 22255 | |
| 22256 | // Complete the authenticated request. |
| 22257 | rv = trans_auth->RestartWithCertificate(identity->certificate(), |
| 22258 | identity->ssl_private_key(), |
| 22259 | callback_auth.callback()); |
| 22260 | EXPECT_THAT(callback_auth.GetResult(rv), IsOk()); |
| 22261 | std::string response_auth; |
| 22262 | EXPECT_THAT(ReadTransaction(trans_auth.get(), &response_auth), IsOk()); |
| 22263 | EXPECT_EQ("auth", response_auth); |
| 22264 | trans_auth.reset(); |
| 22265 | |
| 22266 | // Complete the long-lived requests. |
| 22267 | data_long_lived.Resume(); |
| 22268 | EXPECT_THAT(callback_long_lived.GetResult(ERR_IO_PENDING), IsOk()); |
| 22269 | std::string response_long_lived; |
| 22270 | EXPECT_THAT(ReadTransaction(trans_long_lived.get(), &response_long_lived), |
| 22271 | IsOk()); |
| 22272 | EXPECT_EQ("long-lived", response_long_lived); |
| 22273 | trans_long_lived.reset(); |
| 22274 | |
| 22275 | data_bar.Resume(); |
| 22276 | EXPECT_THAT(callback_long_lived_bar.GetResult(ERR_IO_PENDING), IsOk()); |
| 22277 | std::string response_long_lived_bar; |
| 22278 | EXPECT_THAT( |
| 22279 | ReadTransaction(trans_long_lived_bar.get(), &response_long_lived_bar), |
| 22280 | IsOk()); |
| 22281 | EXPECT_EQ("long-lived", response_long_lived_bar); |
| 22282 | trans_long_lived_bar.reset(); |
| 22283 | |
| 22284 | // Run the post-authentication requests. |
| 22285 | TestCompletionCallback callback_post_auth; |
| 22286 | auto trans_post_auth = |
| 22287 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22288 | rv = trans_post_auth->Start(&request_post_auth, callback_post_auth.callback(), |
| 22289 | NetLogWithSource()); |
| 22290 | EXPECT_THAT(callback_post_auth.GetResult(rv), IsOk()); |
| 22291 | std::string response_post_auth; |
| 22292 | EXPECT_THAT(ReadTransaction(trans_post_auth.get(), &response_post_auth), |
| 22293 | IsOk()); |
| 22294 | EXPECT_EQ("post-auth", response_post_auth); |
| 22295 | trans_post_auth.reset(); |
| 22296 | |
| 22297 | TestCompletionCallback callback_post_auth_bar; |
| 22298 | auto trans_post_auth_bar = |
| 22299 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 22300 | rv = trans_post_auth_bar->Start(&request_post_auth_bar, |
| 22301 | callback_post_auth_bar.callback(), |
| 22302 | NetLogWithSource()); |
| 22303 | EXPECT_THAT(callback_post_auth_bar.GetResult(rv), IsOk()); |
| 22304 | std::string response_post_auth_bar; |
| 22305 | EXPECT_THAT( |
| 22306 | ReadTransaction(trans_post_auth_bar.get(), &response_post_auth_bar), |
| 22307 | IsOk()); |
| 22308 | EXPECT_EQ("post-auth", response_post_auth_bar); |
| 22309 | trans_post_auth_bar.reset(); |
| 22310 | } |
| 22311 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 22312 | } // namespace net |