[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 18 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 19 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 20 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 21 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 22 | #include "base/logging.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 25 | #include "base/optional.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 26 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 28 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 30 | #include "base/strings/stringprintf.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 32 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 33 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 34 | #include "base/test/simple_test_clock.h" |
| 35 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 36 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 37 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 38 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 39 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 40 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 41 | #include "net/base/elements_upload_data_stream.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 42 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 43 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 44 | #include "net/base/load_timing_info.h" |
| 45 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 46 | #include "net/base/net_errors.h" |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 47 | #include "net/base/privacy_mode.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 48 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 49 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 50 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 51 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 52 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 53 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 54 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 55 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 56 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 57 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 58 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 59 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 60 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 61 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 62 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 63 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 64 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 65 | #include "net/http/http_network_session_peer.h" |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 66 | #include "net/http/http_proxy_connect_job.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 67 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 68 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 69 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 70 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 71 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 72 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 73 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 74 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 75 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 76 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 77 | #include "net/log/test_net_log_entry.h" |
| 78 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 79 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 80 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 81 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 82 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 83 | #include "net/proxy_resolution/proxy_resolver.h" |
| 84 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 85 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 86 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 87 | #include "net/socket/client_socket_pool_manager.h" |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 88 | #include "net/socket/connect_job.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 89 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 90 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 91 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 92 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 93 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 94 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 95 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 96 | #include "net/spdy/spdy_session.h" |
| 97 | #include "net/spdy/spdy_session_pool.h" |
| 98 | #include "net/spdy/spdy_test_util_common.h" |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame^] | 99 | #include "net/ssl/client_cert_identity_test_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 100 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 101 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 102 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 103 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 104 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 105 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 106 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 107 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 108 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 109 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 110 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 111 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 112 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 113 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 114 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 115 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 116 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 117 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 118 | #if defined(NTLM_PORTABLE) |
| 119 | #include "base/base64.h" |
| 120 | #include "net/ntlm/ntlm_test_data.h" |
| 121 | #endif |
| 122 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 123 | #if BUILDFLAG(ENABLE_REPORTING) |
| 124 | #include "net/network_error_logging/network_error_logging_service.h" |
| 125 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 126 | #include "net/reporting/reporting_cache.h" |
| 127 | #include "net/reporting/reporting_client.h" |
| 128 | #include "net/reporting/reporting_header_parser.h" |
| 129 | #include "net/reporting/reporting_service.h" |
| 130 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 131 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 132 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 133 | using net::test::IsError; |
| 134 | using net::test::IsOk; |
| 135 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 136 | using base::ASCIIToUTF16; |
| 137 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 138 | using testing::AnyOf; |
| 139 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 140 | //----------------------------------------------------------------------------- |
| 141 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | namespace net { |
| 143 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 144 | namespace { |
| 145 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 146 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 147 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 148 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 149 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 150 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 151 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 152 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 153 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 154 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 155 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 156 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 157 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 158 | const char kAlternativeServiceHttpHeader[] = |
| 159 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 160 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 161 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 162 | return session |
| 163 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 164 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 165 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 166 | } |
| 167 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 169 | return session |
| 170 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 171 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 172 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 173 | } |
| 174 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 175 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 176 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 177 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 178 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 179 | if (!params) |
| 180 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 181 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 182 | if (!params->GetList("headers", &header_list)) |
| 183 | return false; |
| 184 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 185 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 186 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 187 | return true; |
| 188 | } |
| 189 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 190 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 191 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 192 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 194 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 195 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 197 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 198 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 199 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 201 | |
| 202 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 203 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 204 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 205 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 206 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 207 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 210 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 211 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 212 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 213 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 215 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | |
| 217 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 218 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 219 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 220 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 221 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 222 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 223 | load_timing_info.send_start); |
| 224 | |
| 225 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 227 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 228 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 229 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 230 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 234 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 235 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 237 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 239 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 240 | |
| 241 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 242 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 243 | load_timing_info.proxy_resolve_end); |
| 244 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 245 | load_timing_info.send_start); |
| 246 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 247 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 248 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 250 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 251 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 255 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 256 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | int connect_timing_flags) { |
| 258 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 259 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 260 | |
| 261 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 262 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 263 | load_timing_info.proxy_resolve_end); |
| 264 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 265 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 266 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 267 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 268 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 269 | load_timing_info.send_start); |
| 270 | |
| 271 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 273 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 274 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 275 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 276 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 277 | } |
| 278 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 279 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 280 | // result to return. |
| 281 | class CapturingProxyResolver : public ProxyResolver { |
| 282 | public: |
| 283 | CapturingProxyResolver() |
| 284 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 285 | ~CapturingProxyResolver() override = default; |
| 286 | |
| 287 | int GetProxyForURL(const GURL& url, |
| 288 | ProxyInfo* results, |
| 289 | CompletionOnceCallback callback, |
| 290 | std::unique_ptr<Request>* request, |
| 291 | const NetLogWithSource& net_log) override { |
| 292 | results->UseProxyServer(proxy_server_); |
| 293 | resolved_.push_back(url); |
| 294 | return OK; |
| 295 | } |
| 296 | |
| 297 | // Sets whether the resolver should use direct connections, instead of a |
| 298 | // proxy. |
| 299 | void set_proxy_server(ProxyServer proxy_server) { |
| 300 | proxy_server_ = proxy_server; |
| 301 | } |
| 302 | |
| 303 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 304 | |
| 305 | private: |
| 306 | std::vector<GURL> resolved_; |
| 307 | |
| 308 | ProxyServer proxy_server_; |
| 309 | |
| 310 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 311 | }; |
| 312 | |
| 313 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 314 | public: |
| 315 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 316 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 317 | |
| 318 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 319 | std::unique_ptr<ProxyResolver>* resolver, |
| 320 | CompletionOnceCallback callback, |
| 321 | std::unique_ptr<Request>* request) override { |
| 322 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 323 | return OK; |
| 324 | } |
| 325 | |
| 326 | private: |
| 327 | ProxyResolver* resolver_; |
| 328 | }; |
| 329 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 330 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 331 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 332 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 333 | } |
| 334 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 335 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 336 | public: |
| 337 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 338 | |
| 339 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 340 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 341 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 342 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 343 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 344 | return ERR_PAC_SCRIPT_FAILED; |
| 345 | } |
| 346 | }; |
| 347 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 348 | class TestSSLConfigService : public SSLConfigService { |
| 349 | public: |
| 350 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 351 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 352 | |
| 353 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 354 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 355 | bool CanShareConnectionWithClientCerts( |
| 356 | const std::string& hostname) const override { |
| 357 | return false; |
| 358 | } |
| 359 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 360 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 361 | SSLConfig config_; |
| 362 | }; |
| 363 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 364 | } // namespace |
| 365 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 366 | class HttpNetworkTransactionTest : public PlatformTest, |
| 367 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 368 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 369 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 370 | // Important to restore the per-pool limit first, since the pool limit must |
| 371 | // always be greater than group limit, and the tests reduce both limits. |
| 372 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 373 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 374 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 375 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 376 | } |
| 377 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 378 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 379 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 380 | : WithScopedTaskEnvironment( |
| 381 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 382 | base::test::ScopedTaskEnvironment::NowSource:: |
| 383 | MAIN_THREAD_MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 384 | dummy_connect_job_params_( |
| 385 | nullptr /* client_socket_factory */, |
| 386 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 387 | nullptr /* http_auth_cache */, |
| 388 | nullptr /* http_auth_handler_factory */, |
| 389 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 390 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 391 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 392 | nullptr /* proxy_delegate */, |
| 393 | nullptr /* http_user_agent_settings */, |
| 394 | SSLClientSocketContext(), |
| 395 | SSLClientSocketContext(), |
| 396 | nullptr /* socket_performance_watcher_factory */, |
| 397 | nullptr /* network_quality_estimator */, |
| 398 | nullptr /* net_log */, |
| 399 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 400 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 401 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 402 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 403 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 404 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 405 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 406 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 407 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 408 | struct SimpleGetHelperResult { |
| 409 | int rv; |
| 410 | std::string status_line; |
| 411 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 412 | int64_t total_received_bytes; |
| 413 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 414 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 415 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 416 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 417 | }; |
| 418 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 419 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 420 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 421 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 422 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 423 | // before incrementing the counter does not return a null value. |
| 424 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 425 | } |
| 426 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 427 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 428 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 429 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 430 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 431 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 432 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 433 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 434 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 435 | } |
| 436 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 437 | void Check100ResponseTiming(bool use_spdy); |
| 438 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 439 | // Either |write_failure| specifies a write failure or |read_failure| |
| 440 | // specifies a read failure when using a reused socket. In either case, the |
| 441 | // failure should cause the network transaction to resend the request, and the |
| 442 | // other argument should be NULL. |
| 443 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 444 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 445 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 446 | // Either |write_failure| specifies a write failure or |read_failure| |
| 447 | // specifies a read failure when using a reused socket. In either case, the |
| 448 | // failure should cause the network transaction to resend the request, and the |
| 449 | // other argument should be NULL. |
| 450 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 451 | const MockRead* read_failure, |
| 452 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 453 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 454 | SimpleGetHelperResult SimpleGetHelperForData( |
| 455 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 456 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 457 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 458 | HttpRequestInfo request; |
| 459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 460 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 461 | request.traffic_annotation = |
| 462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 464 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 465 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 468 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 469 | for (auto* provider : providers) { |
| 470 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 471 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 473 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 475 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 478 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 479 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 480 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 481 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 482 | |
| 483 | // Even in the failure cases that use this function, connections are always |
| 484 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 485 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 486 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 487 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 488 | if (out.rv != OK) |
| 489 | return out; |
| 490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 491 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 492 | // Can't use ASSERT_* inside helper functions like this, so |
| 493 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 494 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 495 | out.rv = ERR_UNEXPECTED; |
| 496 | return out; |
| 497 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 498 | out.status_line = response->headers->GetStatusLine(); |
| 499 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 500 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 501 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 502 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 503 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 505 | EXPECT_EQ(got_endpoint, |
| 506 | out.remote_endpoint_after_start.address().size() > 0); |
| 507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 510 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 511 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 512 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 513 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 514 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 515 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 516 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 517 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 518 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 519 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 520 | std::string line; |
| 521 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 522 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 523 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 524 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 525 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 526 | std::string value; |
| 527 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 528 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 529 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 530 | EXPECT_EQ("keep-alive", value); |
| 531 | |
| 532 | std::string response_headers; |
| 533 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 534 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 535 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 537 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 538 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 539 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 541 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 542 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 543 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 544 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 545 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 546 | MockWrite data_writes[] = { |
| 547 | MockWrite("GET / HTTP/1.1\r\n" |
| 548 | "Host: www.example.org\r\n" |
| 549 | "Connection: keep-alive\r\n\r\n"), |
| 550 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 551 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 552 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 553 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 554 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 555 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 556 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 557 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 558 | } |
| 559 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 560 | void AddSSLSocketData() { |
| 561 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 562 | ssl_.ssl_info.cert = |
| 563 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 564 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 566 | } |
| 567 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 568 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 569 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 570 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 571 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 572 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 573 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 574 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 575 | const CommonConnectJobParams dummy_connect_job_params_; |
| 576 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 577 | // These clocks are defined here, even though they're only used in the |
| 578 | // Reporting tests below, since they need to be destroyed after |
| 579 | // |session_deps_|. |
| 580 | base::SimpleTestClock clock_; |
| 581 | base::SimpleTestTickClock tick_clock_; |
| 582 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 583 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 584 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 585 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 586 | |
| 587 | // Original socket limits. Some tests set these. Safest to always restore |
| 588 | // them once each test has been run. |
| 589 | int old_max_group_sockets_; |
| 590 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 591 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 592 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 593 | namespace { |
| 594 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 595 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 596 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | BeforeHeadersSentHandler() |
| 598 | : observed_before_headers_sent_with_proxy_(false), |
| 599 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 600 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 601 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 602 | HttpRequestHeaders* request_headers) { |
| 603 | observed_before_headers_sent_ = true; |
| 604 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 605 | !proxy_info.is_quic()) { |
| 606 | return; |
| 607 | } |
| 608 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 609 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 610 | } |
| 611 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 612 | bool observed_before_headers_sent_with_proxy() const { |
| 613 | return observed_before_headers_sent_with_proxy_; |
| 614 | } |
| 615 | |
| 616 | bool observed_before_headers_sent() const { |
| 617 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | std::string observed_proxy_server_uri() const { |
| 621 | return observed_proxy_server_uri_; |
| 622 | } |
| 623 | |
| 624 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 625 | bool observed_before_headers_sent_with_proxy_; |
| 626 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 627 | std::string observed_proxy_server_uri_; |
| 628 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 629 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 630 | }; |
| 631 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 632 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 633 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 634 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 635 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 636 | const int sizeof_row = strlen(row); |
| 637 | const int num_rows = static_cast<int>( |
| 638 | ceil(static_cast<float>(size) / sizeof_row)); |
| 639 | const int sizeof_data = num_rows * sizeof_row; |
| 640 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 641 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 642 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 643 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 644 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 645 | } |
| 646 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 647 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 648 | uint64_t MockGetMSTime() { |
| 649 | // Tue, 23 May 2017 20:13:07 +0000 |
| 650 | return 131400439870000000; |
| 651 | } |
| 652 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 653 | // Alternative functions that eliminate randomness and dependency on the local |
| 654 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 655 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 656 | // This is set to 0xaa because the client challenge for testing in |
| 657 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 658 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 659 | } |
| 660 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 661 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 662 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 663 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 664 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 665 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 666 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 667 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 668 | explicit CaptureGroupIdTransportSocketPool( |
| 669 | const CommonConnectJobParams* common_connect_job_params) |
| 670 | : TransportClientSocketPool(0, |
| 671 | 0, |
| 672 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 673 | ProxyServer::Direct(), |
| 674 | false /* is_for_websockets */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 675 | common_connect_job_params, |
| 676 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 677 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 678 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 679 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 680 | } |
| 681 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 682 | bool socket_requested() const { return socket_requested_; } |
| 683 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 684 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 685 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 686 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | f09e64c | 2019-04-23 22:16:28 | [diff] [blame] | 687 | const base::Optional<NetworkTrafficAnnotationTag>& proxy_annotation_tag, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 688 | RequestPriority priority, |
| 689 | const SocketTag& socket_tag, |
| 690 | ClientSocketPool::RespectLimits respect_limits, |
| 691 | ClientSocketHandle* handle, |
| 692 | CompletionOnceCallback callback, |
| 693 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 694 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 695 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 696 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 697 | return ERR_IO_PENDING; |
| 698 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 699 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
Matt Menke | 7eb405e | 2019-04-25 20:48:21 | [diff] [blame] | 700 | ClientSocketHandle* handle, |
| 701 | bool cancel_connect_job) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 702 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 703 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 704 | int64_t generation) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 705 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 706 | void CloseIdleSocketsInGroup( |
| 707 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 708 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 709 | size_t IdleSocketCountInGroup( |
| 710 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 711 | return 0; |
| 712 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 713 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 714 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 715 | return LOAD_STATE_IDLE; |
| 716 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 717 | |
| 718 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 719 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 720 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 721 | }; |
| 722 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 723 | //----------------------------------------------------------------------------- |
| 724 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 725 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 726 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 727 | bool CheckBasicServerAuth( |
| 728 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 729 | if (!auth_challenge) |
| 730 | return false; |
| 731 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 732 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 733 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 734 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 735 | return true; |
| 736 | } |
| 737 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame^] | 738 | bool CheckBasicSecureServerAuth( |
| 739 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
| 740 | if (!auth_challenge) |
| 741 | return false; |
| 742 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 743 | EXPECT_EQ("https://www.example.org", auth_challenge->challenger.Serialize()); |
| 744 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 745 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 746 | return true; |
| 747 | } |
| 748 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 749 | bool CheckBasicProxyAuth( |
| 750 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 751 | if (!auth_challenge) |
| 752 | return false; |
| 753 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 754 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 755 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 756 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 757 | return true; |
| 758 | } |
| 759 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 760 | bool CheckBasicSecureProxyAuth( |
| 761 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 762 | if (!auth_challenge) |
| 763 | return false; |
| 764 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 765 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 766 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 767 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | return true; |
| 769 | } |
| 770 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 771 | bool CheckDigestServerAuth( |
| 772 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 773 | if (!auth_challenge) |
| 774 | return false; |
| 775 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 776 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 777 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 778 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 779 | return true; |
| 780 | } |
| 781 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 782 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 783 | bool CheckNTLMServerAuth( |
| 784 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 785 | if (!auth_challenge) |
| 786 | return false; |
| 787 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 788 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 790 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 791 | return true; |
| 792 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 793 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 794 | bool CheckNTLMProxyAuth( |
| 795 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 796 | if (!auth_challenge) |
| 797 | return false; |
| 798 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 799 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 800 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 801 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 802 | return true; |
| 803 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 804 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 805 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 806 | } // namespace |
| 807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 808 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 811 | } |
| 812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 813 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 815 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 816 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 817 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 819 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 820 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 822 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 823 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 824 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 825 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 826 | |
| 827 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 831 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 833 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 835 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 836 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 837 | EXPECT_THAT(out.rv, IsOk()); |
| 838 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 839 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 840 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 841 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | } |
| 843 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 844 | // Response with no status line, and a weird port. Should fail by default. |
| 845 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 846 | MockRead data_reads[] = { |
| 847 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 848 | }; |
| 849 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 850 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 852 | |
| 853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 854 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 855 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 856 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 857 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 858 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 859 | request.method = "GET"; |
| 860 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 861 | request.traffic_annotation = |
| 862 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 863 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 864 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 865 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 866 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 867 | } |
| 868 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 869 | // Tests that request info can be destroyed after the headers phase is complete. |
| 870 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 871 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 872 | auto trans = |
| 873 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 874 | |
| 875 | MockRead data_reads[] = { |
| 876 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 877 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 878 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 879 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 881 | |
| 882 | TestCompletionCallback callback; |
| 883 | |
| 884 | { |
| 885 | auto request = std::make_unique<HttpRequestInfo>(); |
| 886 | request->method = "GET"; |
| 887 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 888 | request->traffic_annotation = |
| 889 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 890 | |
| 891 | int rv = |
| 892 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 893 | |
| 894 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 895 | } // Let request info be destroyed. |
| 896 | |
| 897 | trans.reset(); |
| 898 | } |
| 899 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 900 | // Response with no status line, and a weird port. Option to allow weird ports |
| 901 | // enabled. |
| 902 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 903 | MockRead data_reads[] = { |
| 904 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 905 | }; |
| 906 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 907 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 909 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 911 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 912 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 913 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 914 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 915 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 916 | request.method = "GET"; |
| 917 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 918 | request.traffic_annotation = |
| 919 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 920 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 921 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 922 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 923 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 924 | |
| 925 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 926 | ASSERT_TRUE(info->headers); |
| 927 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 928 | |
| 929 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 930 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 931 | } |
| 932 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 934 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 935 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 936 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 937 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 939 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 940 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 942 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 943 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 944 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 948 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 950 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 951 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 952 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 953 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 954 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 956 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 957 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 958 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 962 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 963 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 964 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 966 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 967 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 968 | EXPECT_THAT(out.rv, IsOk()); |
| 969 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 970 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 971 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 972 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 976 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 977 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 978 | MockRead("\n"), |
| 979 | MockRead("\n"), |
| 980 | MockRead("Q"), |
| 981 | MockRead("J"), |
| 982 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 984 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 985 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 986 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 987 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 988 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 989 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 990 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 995 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 996 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 997 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 998 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 999 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1000 | EXPECT_THAT(out.rv, IsOk()); |
| 1001 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1002 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1003 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1004 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1007 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1008 | // persistent connection. The response should still terminate since a 204 |
| 1009 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1010 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1011 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1012 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1013 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1014 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1015 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1016 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1017 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1018 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1019 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1020 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1021 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1022 | int64_t response_size = reads_size - strlen(junk); |
| 1023 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1026 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1027 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1028 | std::string final_chunk = "0\r\n\r\n"; |
| 1029 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1030 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1031 | MockRead data_reads[] = { |
| 1032 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1033 | MockRead("5\r\nHello\r\n"), |
| 1034 | MockRead("1\r\n"), |
| 1035 | MockRead(" \r\n"), |
| 1036 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1037 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1038 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1040 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1041 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1042 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1043 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1044 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1045 | int64_t response_size = reads_size - extra_data.size(); |
| 1046 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1047 | } |
| 1048 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1049 | // Next tests deal with http://crbug.com/56344. |
| 1050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1051 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1052 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1053 | MockRead data_reads[] = { |
| 1054 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1055 | MockRead("Content-Length: 10\r\n"), |
| 1056 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1057 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1058 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1059 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1060 | } |
| 1061 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1062 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1063 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1064 | MockRead data_reads[] = { |
| 1065 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1068 | MockRead("Hello"), |
| 1069 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1070 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1071 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1072 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1073 | EXPECT_EQ("Hello", out.response_data); |
| 1074 | } |
| 1075 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1076 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1077 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1078 | // More than 2 dupes. |
| 1079 | { |
| 1080 | MockRead data_reads[] = { |
| 1081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n"), |
| 1084 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1085 | MockRead("Hello"), |
| 1086 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1087 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1088 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1089 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1090 | EXPECT_EQ("Hello", out.response_data); |
| 1091 | } |
| 1092 | // HTTP/1.0 |
| 1093 | { |
| 1094 | MockRead data_reads[] = { |
| 1095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1096 | MockRead("Content-Length: 5\r\n"), |
| 1097 | MockRead("Content-Length: 5\r\n"), |
| 1098 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1099 | MockRead("Hello"), |
| 1100 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1101 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1102 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1103 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1104 | EXPECT_EQ("Hello", out.response_data); |
| 1105 | } |
| 1106 | // 2 dupes and one mismatched. |
| 1107 | { |
| 1108 | MockRead data_reads[] = { |
| 1109 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1110 | MockRead("Content-Length: 10\r\n"), |
| 1111 | MockRead("Content-Length: 10\r\n"), |
| 1112 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1113 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1114 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1115 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1119 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1120 | MultipleContentLengthHeadersTransferEncoding) { |
| 1121 | MockRead data_reads[] = { |
| 1122 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1123 | MockRead("Content-Length: 666\r\n"), |
| 1124 | MockRead("Content-Length: 1337\r\n"), |
| 1125 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1126 | MockRead("5\r\nHello\r\n"), |
| 1127 | MockRead("1\r\n"), |
| 1128 | MockRead(" \r\n"), |
| 1129 | MockRead("5\r\nworld\r\n"), |
| 1130 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1131 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1133 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1134 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1135 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1136 | EXPECT_EQ("Hello world", out.response_data); |
| 1137 | } |
| 1138 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | // Next tests deal with http://crbug.com/98895. |
| 1140 | |
| 1141 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1142 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1143 | MockRead data_reads[] = { |
| 1144 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1145 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1146 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1147 | MockRead("Hello"), |
| 1148 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1149 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1150 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1152 | EXPECT_EQ("Hello", out.response_data); |
| 1153 | } |
| 1154 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1155 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1156 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | MockRead data_reads[] = { |
| 1158 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1159 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1160 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1161 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1162 | MockRead("Hello"), |
| 1163 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1164 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1165 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1166 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1167 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1171 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | MockRead data_reads[] = { |
| 1173 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1174 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1175 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1176 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1177 | MockRead("Hello"), |
| 1178 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1179 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1180 | EXPECT_THAT(out.rv, |
| 1181 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | } |
| 1183 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1184 | // Checks that two identical Location headers result in no error. |
| 1185 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1186 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | MockRead data_reads[] = { |
| 1188 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1189 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1190 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1192 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | }; |
| 1194 | |
| 1195 | HttpRequestInfo request; |
| 1196 | request.method = "GET"; |
| 1197 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1198 | request.traffic_annotation = |
| 1199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1204 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1207 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1209 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1212 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1214 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1215 | ASSERT_TRUE(response); |
| 1216 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1217 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1218 | std::string url; |
| 1219 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1220 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1221 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1222 | } |
| 1223 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1224 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1225 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1226 | MockRead data_reads[] = { |
| 1227 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1228 | MockRead("Location: http://good.com/\r\n"), |
| 1229 | MockRead("Location: http://evil.com/\r\n"), |
| 1230 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1231 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1232 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1233 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1234 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1235 | } |
| 1236 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1238 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1239 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1240 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1242 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1243 | request.traffic_annotation = |
| 1244 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1246 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1247 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1248 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1249 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1250 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1251 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1252 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1253 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1254 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1255 | "Host: www.example.org\r\n" |
| 1256 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | }; |
| 1258 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1259 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1260 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1262 | // No response body because the test stops reading here. |
| 1263 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1264 | }; |
| 1265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1266 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1267 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1269 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1271 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1273 | |
| 1274 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1277 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1278 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1279 | |
| 1280 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1281 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1282 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1283 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1284 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1285 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1286 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1287 | |
| 1288 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1289 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1290 | bool has_server_header = response->headers->EnumerateHeader( |
| 1291 | &iter, "Server", &server_header); |
| 1292 | EXPECT_TRUE(has_server_header); |
| 1293 | EXPECT_EQ("Blah", server_header); |
| 1294 | |
| 1295 | // Reading should give EOF right away, since there is no message body |
| 1296 | // (despite non-zero content-length). |
| 1297 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1298 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1299 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1300 | EXPECT_EQ("", response_data); |
| 1301 | } |
| 1302 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1303 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | |
| 1306 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1307 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1308 | MockRead("hello"), |
| 1309 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1310 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1311 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1313 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1316 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | "hello", "world" |
| 1318 | }; |
| 1319 | |
| 1320 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1321 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1323 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1324 | request.traffic_annotation = |
| 1325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1327 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1329 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | |
| 1334 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1335 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1336 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1337 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1338 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1340 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1341 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1342 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | |
| 1344 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1345 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1346 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1347 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1351 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1352 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1353 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1354 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1355 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1356 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1357 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | request.method = "POST"; |
| 1359 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1360 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1361 | request.traffic_annotation = |
| 1362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1364 | // Check the upload progress returned before initialization is correct. |
| 1365 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1366 | EXPECT_EQ(0u, progress.size()); |
| 1367 | EXPECT_EQ(0u, progress.position()); |
| 1368 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1371 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1373 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1374 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1375 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1376 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1377 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1378 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1379 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1381 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1382 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1383 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1385 | |
| 1386 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1387 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1389 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1390 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1391 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1392 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1393 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1394 | |
| 1395 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1396 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1398 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1399 | } |
| 1400 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | // This test is almost the same as Ignores100 above, but the response contains |
| 1402 | // 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] | 1403 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1404 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1405 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | request.method = "GET"; |
| 1407 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1408 | request.traffic_annotation = |
| 1409 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1410 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1412 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1413 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1415 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1416 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1417 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1418 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1419 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1420 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1421 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1422 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1423 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1424 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1425 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1427 | |
| 1428 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1429 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1431 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1432 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1433 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1434 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1435 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1436 | |
| 1437 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1438 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1439 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1440 | EXPECT_EQ("hello world", response_data); |
| 1441 | } |
| 1442 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1443 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1444 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1445 | base::TimeDelta::FromMilliseconds(10); |
| 1446 | |
| 1447 | HttpRequestInfo request; |
| 1448 | request.method = "GET"; |
| 1449 | request.url = GURL("http://www.foo.com/"); |
| 1450 | request.traffic_annotation = |
| 1451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1452 | |
| 1453 | std::vector<MockWrite> data_writes = { |
| 1454 | MockWrite(ASYNC, 0, |
| 1455 | "GET / HTTP/1.1\r\n" |
| 1456 | "Host: www.foo.com\r\n" |
| 1457 | "Connection: keep-alive\r\n\r\n"), |
| 1458 | }; |
| 1459 | |
| 1460 | std::vector<MockRead> data_reads = { |
| 1461 | // Write one byte of the status line, followed by a pause. |
| 1462 | MockRead(ASYNC, 1, "H"), |
| 1463 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1464 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1465 | MockRead(ASYNC, 4, "hello world"), |
| 1466 | MockRead(SYNCHRONOUS, OK, 5), |
| 1467 | }; |
| 1468 | |
| 1469 | SequencedSocketData data(data_reads, data_writes); |
| 1470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1471 | |
| 1472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1473 | |
| 1474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1475 | |
| 1476 | TestCompletionCallback callback; |
| 1477 | |
| 1478 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1480 | |
| 1481 | data.RunUntilPaused(); |
| 1482 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1483 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1484 | data.Resume(); |
| 1485 | |
| 1486 | rv = callback.WaitForResult(); |
| 1487 | EXPECT_THAT(rv, IsOk()); |
| 1488 | |
| 1489 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1490 | ASSERT_TRUE(response); |
| 1491 | |
| 1492 | EXPECT_TRUE(response->headers); |
| 1493 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1494 | |
| 1495 | LoadTimingInfo load_timing_info; |
| 1496 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1497 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1498 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1499 | // Ensure we didn't include the delay in the TTFB time. |
| 1500 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1501 | load_timing_info.connect_timing.connect_end); |
| 1502 | // Ensure that the mock clock advanced at all. |
| 1503 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1504 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1505 | |
| 1506 | std::string response_data; |
| 1507 | rv = ReadTransaction(&trans, &response_data); |
| 1508 | EXPECT_THAT(rv, IsOk()); |
| 1509 | EXPECT_EQ("hello world", response_data); |
| 1510 | } |
| 1511 | |
| 1512 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1513 | // info uses the first response, even if 1XX/informational. |
| 1514 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1515 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1516 | base::TimeDelta::FromMilliseconds(10); |
| 1517 | |
| 1518 | HttpRequestInfo request; |
| 1519 | request.method = "GET"; |
| 1520 | request.url = GURL("https://www.foo.com/"); |
| 1521 | request.traffic_annotation = |
| 1522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1523 | |
| 1524 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1525 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1526 | |
| 1527 | std::vector<MockWrite> data_writes; |
| 1528 | std::vector<MockRead> data_reads; |
| 1529 | |
| 1530 | spdy::SpdySerializedFrame spdy_req( |
| 1531 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1532 | |
| 1533 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1534 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1535 | spdy::SpdySerializedFrame spdy_resp1( |
| 1536 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1537 | spdy::SpdySerializedFrame spdy_resp2( |
| 1538 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1539 | spdy::SpdySerializedFrame spdy_data( |
| 1540 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1541 | |
| 1542 | if (use_spdy) { |
| 1543 | ssl.next_proto = kProtoHTTP2; |
| 1544 | |
| 1545 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1546 | |
| 1547 | data_reads = { |
| 1548 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1549 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1550 | MockRead(SYNCHRONOUS, OK, 5), |
| 1551 | }; |
| 1552 | } else { |
| 1553 | data_writes = { |
| 1554 | MockWrite(ASYNC, 0, |
| 1555 | "GET / HTTP/1.1\r\n" |
| 1556 | "Host: www.foo.com\r\n" |
| 1557 | "Connection: keep-alive\r\n\r\n"), |
| 1558 | }; |
| 1559 | |
| 1560 | data_reads = { |
| 1561 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1562 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1563 | |
| 1564 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1565 | MockRead(ASYNC, 4, "hello world"), |
| 1566 | MockRead(SYNCHRONOUS, OK, 5), |
| 1567 | }; |
| 1568 | } |
| 1569 | |
| 1570 | SequencedSocketData data(data_reads, data_writes); |
| 1571 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1572 | |
| 1573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1574 | |
| 1575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1576 | |
| 1577 | TestCompletionCallback callback; |
| 1578 | |
| 1579 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1581 | |
| 1582 | data.RunUntilPaused(); |
| 1583 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1584 | // the delay before parsing the 200 response. |
| 1585 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1586 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1587 | data.Resume(); |
| 1588 | |
| 1589 | rv = callback.WaitForResult(); |
| 1590 | EXPECT_THAT(rv, IsOk()); |
| 1591 | |
| 1592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1593 | ASSERT_TRUE(response); |
| 1594 | |
| 1595 | LoadTimingInfo load_timing_info; |
| 1596 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1597 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1598 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1599 | // Ensure we didn't include the delay in the TTFB time. |
| 1600 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1601 | load_timing_info.connect_timing.connect_end); |
| 1602 | // Ensure that the mock clock advanced at all. |
| 1603 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1604 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1605 | |
| 1606 | std::string response_data; |
| 1607 | rv = ReadTransaction(&trans, &response_data); |
| 1608 | EXPECT_THAT(rv, IsOk()); |
| 1609 | EXPECT_EQ("hello world", response_data); |
| 1610 | } |
| 1611 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1612 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1613 | Check100ResponseTiming(false /* use_spdy */); |
| 1614 | } |
| 1615 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1616 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1617 | Check100ResponseTiming(true /* use_spdy */); |
| 1618 | } |
| 1619 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1620 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1621 | HttpRequestInfo request; |
| 1622 | request.method = "POST"; |
| 1623 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1624 | request.traffic_annotation = |
| 1625 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1629 | |
| 1630 | MockRead data_reads[] = { |
| 1631 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1632 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1634 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1636 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1637 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1641 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1644 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1645 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1646 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1647 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1648 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1649 | } |
| 1650 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1651 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1652 | HttpRequestInfo request; |
| 1653 | request.method = "POST"; |
| 1654 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1655 | request.traffic_annotation = |
| 1656 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1660 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1661 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1662 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1663 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1664 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1667 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1671 | |
| 1672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1673 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1674 | } |
| 1675 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1676 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1677 | const MockWrite* write_failure, |
| 1678 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1679 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1680 | request.method = "GET"; |
| 1681 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1682 | request.traffic_annotation = |
| 1683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1684 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1685 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1686 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1688 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1689 | // Written data for successfully sending both requests. |
| 1690 | MockWrite data1_writes[] = { |
| 1691 | MockWrite("GET / HTTP/1.1\r\n" |
| 1692 | "Host: www.foo.com\r\n" |
| 1693 | "Connection: keep-alive\r\n\r\n"), |
| 1694 | MockWrite("GET / HTTP/1.1\r\n" |
| 1695 | "Host: www.foo.com\r\n" |
| 1696 | "Connection: keep-alive\r\n\r\n") |
| 1697 | }; |
| 1698 | |
| 1699 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1700 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1701 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1702 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1703 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1704 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1705 | |
| 1706 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1707 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1708 | data1_writes[1] = *write_failure; |
| 1709 | } else { |
| 1710 | ASSERT_TRUE(read_failure); |
| 1711 | data1_reads[2] = *read_failure; |
| 1712 | } |
| 1713 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1714 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1715 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
| 1717 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1718 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1719 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1720 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1721 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1722 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1723 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1724 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1725 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1726 | "hello", "world" |
| 1727 | }; |
| 1728 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1729 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1730 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1731 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1734 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1735 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1737 | |
| 1738 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1739 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1740 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1741 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1742 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1743 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1744 | if (i == 0) { |
| 1745 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1746 | } else { |
| 1747 | // The second request should be using a new socket. |
| 1748 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1749 | } |
| 1750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1751 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1752 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1753 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1754 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1755 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1756 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1757 | |
| 1758 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1759 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1760 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1761 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1762 | } |
| 1763 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1764 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1765 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1766 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1767 | const MockRead* read_failure, |
| 1768 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1769 | HttpRequestInfo request; |
| 1770 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1772 | request.traffic_annotation = |
| 1773 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1774 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1775 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1776 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1778 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1779 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1780 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1781 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1782 | ssl1.next_proto = kProtoHTTP2; |
| 1783 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1784 | } |
| 1785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1787 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1788 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1789 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1790 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1791 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1792 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1793 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1794 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1795 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1796 | // HTTP/1.1 versions of the request and response. |
| 1797 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1798 | "Host: www.foo.com\r\n" |
| 1799 | "Connection: keep-alive\r\n\r\n"; |
| 1800 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1801 | const char kHttpData[] = "hello"; |
| 1802 | |
| 1803 | std::vector<MockRead> data1_reads; |
| 1804 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1805 | if (write_failure) { |
| 1806 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1807 | data1_writes.push_back(*write_failure); |
| 1808 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1809 | } else { |
| 1810 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1811 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1812 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1813 | } else { |
| 1814 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1815 | } |
| 1816 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1817 | } |
| 1818 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1819 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1820 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1821 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1822 | std::vector<MockRead> data2_reads; |
| 1823 | std::vector<MockWrite> data2_writes; |
| 1824 | |
| 1825 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1826 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1827 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1828 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1829 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1830 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1831 | } else { |
| 1832 | data2_writes.push_back( |
| 1833 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1834 | |
| 1835 | data2_reads.push_back( |
| 1836 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1837 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1838 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1839 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1840 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1841 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1842 | |
| 1843 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1844 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1845 | // Wait for the preconnect to complete. |
| 1846 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1847 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1848 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1849 | |
| 1850 | // Make the request. |
| 1851 | TestCompletionCallback callback; |
| 1852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1853 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1854 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1855 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1856 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1857 | |
| 1858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1859 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1860 | |
| 1861 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1862 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1863 | TestLoadTimingNotReused( |
| 1864 | load_timing_info, |
| 1865 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1867 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1868 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1869 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1870 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1871 | if (response->was_fetched_via_spdy) { |
| 1872 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1873 | } else { |
| 1874 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1875 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1876 | |
| 1877 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1878 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1880 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1881 | } |
| 1882 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1883 | // Test that we do not retry indefinitely when a server sends an error like |
| 1884 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1885 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1886 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1887 | HttpRequestInfo request; |
| 1888 | request.method = "GET"; |
| 1889 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1890 | request.traffic_annotation = |
| 1891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1892 | |
| 1893 | // Check whether we give up after the third try. |
| 1894 | |
| 1895 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1896 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1897 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1898 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1899 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1900 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1901 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1902 | |
| 1903 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1904 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1905 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1906 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1907 | |
| 1908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1909 | AddSSLSocketData(); |
| 1910 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1911 | AddSSLSocketData(); |
| 1912 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1913 | AddSSLSocketData(); |
| 1914 | |
| 1915 | TestCompletionCallback callback; |
| 1916 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1917 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1918 | |
| 1919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1921 | |
| 1922 | rv = callback.WaitForResult(); |
| 1923 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1924 | } |
| 1925 | |
| 1926 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1927 | HttpRequestInfo request; |
| 1928 | request.method = "GET"; |
| 1929 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1930 | request.traffic_annotation = |
| 1931 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1932 | |
| 1933 | // Check whether we try atleast thrice before giving up. |
| 1934 | |
| 1935 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1936 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1937 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1938 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1939 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1940 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1941 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1942 | |
| 1943 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1944 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1945 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1946 | spdy::SpdySerializedFrame spdy_data( |
| 1947 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1948 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1949 | CreateMockRead(spdy_data, 2)}; |
| 1950 | |
| 1951 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1952 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1953 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1954 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1955 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1956 | |
| 1957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1958 | AddSSLSocketData(); |
| 1959 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1960 | AddSSLSocketData(); |
| 1961 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1962 | AddSSLSocketData(); |
| 1963 | |
| 1964 | TestCompletionCallback callback; |
| 1965 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1967 | |
| 1968 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1970 | |
| 1971 | rv = callback.WaitForResult(); |
| 1972 | EXPECT_THAT(rv, IsOk()); |
| 1973 | } |
| 1974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1975 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1976 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1977 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1978 | } |
| 1979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1980 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1981 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1982 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1983 | } |
| 1984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1985 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1986 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1987 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1988 | } |
| 1989 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1990 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1991 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1992 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1993 | MockRead read_failure(SYNCHRONOUS, |
| 1994 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1995 | "Connection: Keep-Alive\r\n" |
| 1996 | "Content-Length: 6\r\n\r\n" |
| 1997 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1998 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1999 | } |
| 2000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2001 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2002 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2003 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2004 | } |
| 2005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2006 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2007 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2008 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2009 | } |
| 2010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2011 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2012 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2013 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2014 | } |
| 2015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2016 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2017 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2018 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2019 | } |
| 2020 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2021 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2022 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2023 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2024 | MockRead read_failure(SYNCHRONOUS, |
| 2025 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2026 | "Connection: Keep-Alive\r\n" |
| 2027 | "Content-Length: 6\r\n\r\n" |
| 2028 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2029 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2030 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2031 | } |
| 2032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2033 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2034 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2035 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2036 | } |
| 2037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2038 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2039 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2040 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2041 | } |
| 2042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2043 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2044 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2045 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2046 | } |
| 2047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2048 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2049 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2050 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2051 | } |
| 2052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2053 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2054 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2055 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2056 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2057 | request.traffic_annotation = |
| 2058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2059 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2060 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2061 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2062 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2063 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2064 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2065 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2066 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2067 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2068 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2069 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2070 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2072 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2073 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2074 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2076 | |
| 2077 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2078 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2079 | |
| 2080 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2081 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2082 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | // What do various browsers do when the server closes a non-keepalive |
| 2086 | // connection without sending any response header or body? |
| 2087 | // |
| 2088 | // IE7: error page |
| 2089 | // Safari 3.1.2 (Windows): error page |
| 2090 | // Firefox 3.0.1: blank page |
| 2091 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2092 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2093 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2094 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2095 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2096 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2097 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2098 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2099 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2100 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2101 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2102 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2103 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2104 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2105 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2106 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2107 | // destructor in such situations. |
| 2108 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2109 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2110 | HttpRequestInfo request; |
| 2111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2112 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2113 | request.traffic_annotation = |
| 2114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2115 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2117 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2118 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2119 | |
| 2120 | MockRead data_reads[] = { |
| 2121 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2122 | MockRead("Connection: keep-alive\r\n"), |
| 2123 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2124 | MockRead("hello"), |
| 2125 | MockRead(SYNCHRONOUS, 0), |
| 2126 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2127 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2128 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2129 | |
| 2130 | TestCompletionCallback callback; |
| 2131 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2132 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2134 | |
| 2135 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2137 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2138 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2139 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2140 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2141 | if (rv == ERR_IO_PENDING) |
| 2142 | rv = callback.WaitForResult(); |
| 2143 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2144 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2145 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2146 | |
| 2147 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2148 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2149 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2150 | } |
| 2151 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2152 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2153 | HttpRequestInfo request; |
| 2154 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2155 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2156 | request.traffic_annotation = |
| 2157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2158 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2160 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2161 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2162 | |
| 2163 | MockRead data_reads[] = { |
| 2164 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2165 | MockRead("Connection: keep-alive\r\n"), |
| 2166 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2167 | MockRead(SYNCHRONOUS, 0), |
| 2168 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2169 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2170 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2171 | |
| 2172 | TestCompletionCallback callback; |
| 2173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2174 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2176 | |
| 2177 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2179 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2180 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2181 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2182 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2183 | if (rv == ERR_IO_PENDING) |
| 2184 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2185 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2186 | |
| 2187 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2188 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2189 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2190 | } |
| 2191 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2192 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2193 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2194 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2195 | HttpRequestInfo request; |
| 2196 | request.method = "GET"; |
| 2197 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2198 | request.traffic_annotation = |
| 2199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2200 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2201 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2202 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2204 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2205 | const char* request_data = |
| 2206 | "GET / HTTP/1.1\r\n" |
| 2207 | "Host: www.foo.com\r\n" |
| 2208 | "Connection: keep-alive\r\n\r\n"; |
| 2209 | MockWrite data_writes[] = { |
| 2210 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2211 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2212 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2213 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2214 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2215 | }; |
| 2216 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2217 | // Note that because all these reads happen in the same |
| 2218 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2219 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2220 | MockRead data_reads[] = { |
| 2221 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2222 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2223 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2224 | MockRead(ASYNC, 7, |
| 2225 | "HTTP/1.1 302 Found\r\n" |
| 2226 | "Content-Length: 0\r\n\r\n"), |
| 2227 | MockRead(ASYNC, 9, |
| 2228 | "HTTP/1.1 302 Found\r\n" |
| 2229 | "Content-Length: 5\r\n\r\n" |
| 2230 | "hello"), |
| 2231 | MockRead(ASYNC, 11, |
| 2232 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2233 | "Content-Length: 0\r\n\r\n"), |
| 2234 | MockRead(ASYNC, 13, |
| 2235 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2236 | "Content-Length: 5\r\n\r\n" |
| 2237 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2238 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2239 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2240 | // the set_busy_before_sync_reads(true) call, while the |
| 2241 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2242 | // reuseable. See http://crbug.com/544255. |
| 2243 | MockRead(ASYNC, 15, |
| 2244 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2245 | "Content-Length: 5\r\n\r\n"), |
| 2246 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2247 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2248 | MockRead(ASYNC, 18, |
| 2249 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2250 | "Content-Length: 5\r\n\r\n" |
| 2251 | "he"), |
| 2252 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2253 | |
| 2254 | // The body of the final request is actually read. |
| 2255 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2256 | MockRead(ASYNC, 22, "hello"), |
| 2257 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2258 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2259 | data.set_busy_before_sync_reads(true); |
| 2260 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2261 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2262 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2263 | std::string response_lines[kNumUnreadBodies]; |
| 2264 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2265 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2266 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2267 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2268 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2269 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2270 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2271 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2272 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2273 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2274 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2275 | LoadTimingInfo load_timing_info; |
| 2276 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2277 | if (i == 0) { |
| 2278 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2279 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2280 | } else { |
| 2281 | TestLoadTimingReused(load_timing_info); |
| 2282 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2283 | } |
| 2284 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2285 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2286 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2287 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2288 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2289 | response_lines[i] = response->headers->GetStatusLine(); |
| 2290 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2291 | // Delete the transaction without reading the response bodies. Then spin |
| 2292 | // the message loop, so the response bodies are drained. |
| 2293 | trans.reset(); |
| 2294 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2295 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2296 | |
| 2297 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2298 | "HTTP/1.1 204 No Content", |
| 2299 | "HTTP/1.1 205 Reset Content", |
| 2300 | "HTTP/1.1 304 Not Modified", |
| 2301 | "HTTP/1.1 302 Found", |
| 2302 | "HTTP/1.1 302 Found", |
| 2303 | "HTTP/1.1 301 Moved Permanently", |
| 2304 | "HTTP/1.1 301 Moved Permanently", |
| 2305 | "HTTP/1.1 200 Hunky-Dory", |
| 2306 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2307 | }; |
| 2308 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2309 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2310 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2311 | |
| 2312 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2313 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2315 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2316 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2317 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2318 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2319 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2320 | ASSERT_TRUE(response); |
| 2321 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2322 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2323 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2324 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2326 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2327 | } |
| 2328 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2329 | // Sockets that receive extra data after a response is complete should not be |
| 2330 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2331 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2333 | MockWrite data_writes1[] = { |
| 2334 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2335 | "Host: www.borked.com\r\n" |
| 2336 | "Connection: keep-alive\r\n\r\n"), |
| 2337 | }; |
| 2338 | |
| 2339 | MockRead data_reads1[] = { |
| 2340 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2341 | "Connection: keep-alive\r\n" |
| 2342 | "Content-Length: 22\r\n\r\n" |
| 2343 | "This server is borked."), |
| 2344 | }; |
| 2345 | |
| 2346 | MockWrite data_writes2[] = { |
| 2347 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2348 | "Host: www.borked.com\r\n" |
| 2349 | "Connection: keep-alive\r\n\r\n"), |
| 2350 | }; |
| 2351 | |
| 2352 | MockRead data_reads2[] = { |
| 2353 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2354 | "Content-Length: 3\r\n\r\n" |
| 2355 | "foo"), |
| 2356 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2357 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2358 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2359 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2360 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2361 | |
| 2362 | TestCompletionCallback callback; |
| 2363 | HttpRequestInfo request1; |
| 2364 | request1.method = "HEAD"; |
| 2365 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2366 | request1.traffic_annotation = |
| 2367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2368 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2369 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2370 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2371 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2372 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2373 | |
| 2374 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2375 | ASSERT_TRUE(response1); |
| 2376 | ASSERT_TRUE(response1->headers); |
| 2377 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2378 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2379 | |
| 2380 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2381 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2382 | EXPECT_EQ("", response_data1); |
| 2383 | // Deleting the transaction attempts to release the socket back into the |
| 2384 | // socket pool. |
| 2385 | trans1.reset(); |
| 2386 | |
| 2387 | HttpRequestInfo request2; |
| 2388 | request2.method = "GET"; |
| 2389 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2390 | request2.traffic_annotation = |
| 2391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2392 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2393 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2394 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2395 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2396 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2397 | |
| 2398 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2399 | ASSERT_TRUE(response2); |
| 2400 | ASSERT_TRUE(response2->headers); |
| 2401 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2402 | |
| 2403 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2404 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2405 | EXPECT_EQ("foo", response_data2); |
| 2406 | } |
| 2407 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2408 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2409 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2410 | MockWrite data_writes1[] = { |
| 2411 | MockWrite("GET / HTTP/1.1\r\n" |
| 2412 | "Host: www.borked.com\r\n" |
| 2413 | "Connection: keep-alive\r\n\r\n"), |
| 2414 | }; |
| 2415 | |
| 2416 | MockRead data_reads1[] = { |
| 2417 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2418 | "Connection: keep-alive\r\n" |
| 2419 | "Content-Length: 22\r\n\r\n" |
| 2420 | "This server is borked." |
| 2421 | "Bonus data!"), |
| 2422 | }; |
| 2423 | |
| 2424 | MockWrite data_writes2[] = { |
| 2425 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2426 | "Host: www.borked.com\r\n" |
| 2427 | "Connection: keep-alive\r\n\r\n"), |
| 2428 | }; |
| 2429 | |
| 2430 | MockRead data_reads2[] = { |
| 2431 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2432 | "Content-Length: 3\r\n\r\n" |
| 2433 | "foo"), |
| 2434 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2435 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2436 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2437 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2438 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2439 | |
| 2440 | TestCompletionCallback callback; |
| 2441 | HttpRequestInfo request1; |
| 2442 | request1.method = "GET"; |
| 2443 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2444 | request1.traffic_annotation = |
| 2445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2446 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2447 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2448 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2449 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2450 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2451 | |
| 2452 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2453 | ASSERT_TRUE(response1); |
| 2454 | ASSERT_TRUE(response1->headers); |
| 2455 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2456 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2457 | |
| 2458 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2459 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2460 | EXPECT_EQ("This server is borked.", response_data1); |
| 2461 | // Deleting the transaction attempts to release the socket back into the |
| 2462 | // socket pool. |
| 2463 | trans1.reset(); |
| 2464 | |
| 2465 | HttpRequestInfo request2; |
| 2466 | request2.method = "GET"; |
| 2467 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2468 | request2.traffic_annotation = |
| 2469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2470 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2471 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2472 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2473 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2474 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2475 | |
| 2476 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2477 | ASSERT_TRUE(response2); |
| 2478 | ASSERT_TRUE(response2->headers); |
| 2479 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2480 | |
| 2481 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2482 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2483 | EXPECT_EQ("foo", response_data2); |
| 2484 | } |
| 2485 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2486 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2488 | MockWrite data_writes1[] = { |
| 2489 | MockWrite("GET / HTTP/1.1\r\n" |
| 2490 | "Host: www.borked.com\r\n" |
| 2491 | "Connection: keep-alive\r\n\r\n"), |
| 2492 | }; |
| 2493 | |
| 2494 | MockRead data_reads1[] = { |
| 2495 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2496 | "Connection: keep-alive\r\n" |
| 2497 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2498 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2499 | MockRead("0\r\n\r\nBonus data!"), |
| 2500 | }; |
| 2501 | |
| 2502 | MockWrite data_writes2[] = { |
| 2503 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2504 | "Host: www.borked.com\r\n" |
| 2505 | "Connection: keep-alive\r\n\r\n"), |
| 2506 | }; |
| 2507 | |
| 2508 | MockRead data_reads2[] = { |
| 2509 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2510 | "Content-Length: 3\r\n\r\n" |
| 2511 | "foo"), |
| 2512 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2513 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2515 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2516 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2517 | |
| 2518 | TestCompletionCallback callback; |
| 2519 | HttpRequestInfo request1; |
| 2520 | request1.method = "GET"; |
| 2521 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2522 | request1.traffic_annotation = |
| 2523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2524 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2525 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2526 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2527 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2528 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2529 | |
| 2530 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2531 | ASSERT_TRUE(response1); |
| 2532 | ASSERT_TRUE(response1->headers); |
| 2533 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2534 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2535 | |
| 2536 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2537 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2538 | EXPECT_EQ("This server is borked.", response_data1); |
| 2539 | // Deleting the transaction attempts to release the socket back into the |
| 2540 | // socket pool. |
| 2541 | trans1.reset(); |
| 2542 | |
| 2543 | HttpRequestInfo request2; |
| 2544 | request2.method = "GET"; |
| 2545 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2546 | request2.traffic_annotation = |
| 2547 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2548 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2549 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2550 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2551 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2552 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2553 | |
| 2554 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2555 | ASSERT_TRUE(response2); |
| 2556 | ASSERT_TRUE(response2->headers); |
| 2557 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2558 | |
| 2559 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2560 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2561 | EXPECT_EQ("foo", response_data2); |
| 2562 | } |
| 2563 | |
| 2564 | // This is a little different from the others - it tests the case that the |
| 2565 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2566 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2567 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2568 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2570 | MockWrite data_writes1[] = { |
| 2571 | MockWrite("GET / HTTP/1.1\r\n" |
| 2572 | "Host: www.borked.com\r\n" |
| 2573 | "Connection: keep-alive\r\n\r\n"), |
| 2574 | }; |
| 2575 | |
| 2576 | MockRead data_reads1[] = { |
| 2577 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2578 | "Connection: keep-alive\r\n" |
| 2579 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2580 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2581 | MockRead("0\r\n\r\nBonus data!"), |
| 2582 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2583 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2584 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2585 | |
| 2586 | TestCompletionCallback callback; |
| 2587 | HttpRequestInfo request1; |
| 2588 | request1.method = "GET"; |
| 2589 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2590 | request1.traffic_annotation = |
| 2591 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2592 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2593 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2594 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2595 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2596 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2597 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2598 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2599 | ASSERT_TRUE(response1); |
| 2600 | ASSERT_TRUE(response1->headers); |
| 2601 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2602 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2603 | |
| 2604 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2605 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2606 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2607 | |
| 2608 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2609 | // socket can't be reused, rather than returning it to the socket pool. |
| 2610 | base::RunLoop().RunUntilIdle(); |
| 2611 | |
| 2612 | // There should be no idle sockets in the pool. |
| 2613 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2614 | } |
| 2615 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2616 | // Test the request-challenge-retry sequence for basic auth. |
| 2617 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2618 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2619 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2620 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2621 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2622 | request.traffic_annotation = |
| 2623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2624 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2625 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2626 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2629 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2630 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2631 | MockWrite( |
| 2632 | "GET / HTTP/1.1\r\n" |
| 2633 | "Host: www.example.org\r\n" |
| 2634 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2635 | }; |
| 2636 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2637 | MockRead data_reads1[] = { |
| 2638 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2639 | // Give a couple authenticate options (only the middle one is actually |
| 2640 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2641 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2642 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2643 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2645 | // Large content-length -- won't matter, as connection will be reset. |
| 2646 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2647 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2648 | }; |
| 2649 | |
| 2650 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2651 | // be issuing -- the final header line contains the credentials. |
| 2652 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2653 | MockWrite( |
| 2654 | "GET / HTTP/1.1\r\n" |
| 2655 | "Host: www.example.org\r\n" |
| 2656 | "Connection: keep-alive\r\n" |
| 2657 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2658 | }; |
| 2659 | |
| 2660 | // Lastly, the server responds with the actual content. |
| 2661 | MockRead data_reads2[] = { |
| 2662 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2663 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2664 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2665 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2666 | }; |
| 2667 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2668 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2669 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2671 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2673 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2675 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2677 | |
| 2678 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2679 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2680 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2681 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2682 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2683 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2684 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2685 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2686 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2687 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2688 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2689 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2690 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2691 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2692 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2694 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2696 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2698 | |
| 2699 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2700 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2701 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2702 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2704 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2705 | // The load timing after restart should have a new socket ID, and times after |
| 2706 | // those of the first load timing. |
| 2707 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2708 | load_timing_info2.connect_timing.connect_start); |
| 2709 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2710 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2711 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2712 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2713 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2714 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2716 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2717 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2718 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2719 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2720 | } |
| 2721 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2722 | // Test the request-challenge-retry sequence for basic auth. |
| 2723 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2724 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2725 | HttpRequestInfo request; |
| 2726 | request.method = "GET"; |
| 2727 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2728 | request.traffic_annotation = |
| 2729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2730 | |
| 2731 | TestNetLog log; |
| 2732 | MockHostResolver* resolver = new MockHostResolver(); |
| 2733 | session_deps_.net_log = &log; |
| 2734 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2735 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2737 | |
| 2738 | resolver->rules()->ClearRules(); |
| 2739 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2740 | |
| 2741 | MockWrite data_writes1[] = { |
| 2742 | MockWrite("GET / HTTP/1.1\r\n" |
| 2743 | "Host: www.example.org\r\n" |
| 2744 | "Connection: keep-alive\r\n\r\n"), |
| 2745 | }; |
| 2746 | |
| 2747 | MockRead data_reads1[] = { |
| 2748 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2749 | // Give a couple authenticate options (only the middle one is actually |
| 2750 | // supported). |
| 2751 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2752 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2753 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2754 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2755 | // Large content-length -- won't matter, as connection will be reset. |
| 2756 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2757 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2758 | }; |
| 2759 | |
| 2760 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2761 | // be issuing -- the final header line contains the credentials. |
| 2762 | MockWrite data_writes2[] = { |
| 2763 | MockWrite("GET / HTTP/1.1\r\n" |
| 2764 | "Host: www.example.org\r\n" |
| 2765 | "Connection: keep-alive\r\n" |
| 2766 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2767 | }; |
| 2768 | |
| 2769 | // Lastly, the server responds with the actual content. |
| 2770 | MockRead data_reads2[] = { |
| 2771 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2772 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2773 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2774 | }; |
| 2775 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2776 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2777 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2778 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2779 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2780 | |
| 2781 | TestCompletionCallback callback1; |
| 2782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2783 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2784 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2785 | |
| 2786 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2787 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2788 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2789 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2790 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2791 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2792 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2793 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2795 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2796 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2797 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2798 | |
| 2799 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2800 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2801 | ASSERT_FALSE(endpoint.address().empty()); |
| 2802 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2803 | |
| 2804 | resolver->rules()->ClearRules(); |
| 2805 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2806 | |
| 2807 | TestCompletionCallback callback2; |
| 2808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2809 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2810 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2811 | |
| 2812 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2813 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2814 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2815 | // The load timing after restart should have a new socket ID, and times after |
| 2816 | // those of the first load timing. |
| 2817 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2818 | load_timing_info2.connect_timing.connect_start); |
| 2819 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2821 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2822 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2823 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2824 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2826 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2827 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2828 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2829 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2831 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2832 | ASSERT_FALSE(endpoint.address().empty()); |
| 2833 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2834 | } |
| 2835 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2836 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2837 | // will eventually give up. |
| 2838 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2839 | HttpRequestInfo request; |
| 2840 | request.method = "GET"; |
| 2841 | request.url = GURL("http://www.example.org/"); |
| 2842 | request.traffic_annotation = |
| 2843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2844 | |
| 2845 | TestNetLog log; |
| 2846 | session_deps_.net_log = &log; |
| 2847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2849 | |
| 2850 | MockWrite data_writes[] = { |
| 2851 | MockWrite("GET / HTTP/1.1\r\n" |
| 2852 | "Host: www.example.org\r\n" |
| 2853 | "Connection: keep-alive\r\n\r\n"), |
| 2854 | }; |
| 2855 | |
| 2856 | MockRead data_reads[] = { |
| 2857 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2858 | // Give a couple authenticate options (only the middle one is actually |
| 2859 | // supported). |
| 2860 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2861 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2862 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2863 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2864 | // Large content-length -- won't matter, as connection will be reset. |
| 2865 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2866 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2867 | }; |
| 2868 | |
| 2869 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2870 | // be issuing -- the final header line contains the credentials. |
| 2871 | MockWrite data_writes_restart[] = { |
| 2872 | MockWrite("GET / HTTP/1.1\r\n" |
| 2873 | "Host: www.example.org\r\n" |
| 2874 | "Connection: keep-alive\r\n" |
| 2875 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2876 | }; |
| 2877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2878 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2880 | |
| 2881 | TestCompletionCallback callback; |
| 2882 | int rv = callback.GetResult( |
| 2883 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2884 | |
| 2885 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2886 | for (int i = 0; i < 32; i++) { |
| 2887 | // Check the previous response was a 401. |
| 2888 | EXPECT_THAT(rv, IsOk()); |
| 2889 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2890 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2891 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2892 | |
| 2893 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2894 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2895 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2896 | data_restarts.back().get()); |
| 2897 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2898 | callback.callback())); |
| 2899 | } |
| 2900 | |
| 2901 | // After too many tries, the transaction should have given up. |
| 2902 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2903 | } |
| 2904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2905 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2906 | HttpRequestInfo request; |
| 2907 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2908 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2909 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2910 | request.traffic_annotation = |
| 2911 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2912 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2913 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2914 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2915 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2916 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2917 | MockWrite( |
| 2918 | "GET / HTTP/1.1\r\n" |
| 2919 | "Host: www.example.org\r\n" |
| 2920 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2921 | }; |
| 2922 | |
| 2923 | MockRead data_reads[] = { |
| 2924 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2925 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2926 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2927 | // Large content-length -- won't matter, as connection will be reset. |
| 2928 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2929 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2930 | }; |
| 2931 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2932 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2933 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2934 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2935 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2936 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2938 | |
| 2939 | rv = callback.WaitForResult(); |
| 2940 | EXPECT_EQ(0, rv); |
| 2941 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2942 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2943 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2944 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2945 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2948 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2949 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2950 | } |
| 2951 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2952 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2953 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2954 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2955 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2956 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2957 | // reused. See http://crbug.com/544255. |
| 2958 | for (int i = 0; i < 2; ++i) { |
| 2959 | HttpRequestInfo request; |
| 2960 | request.method = "GET"; |
| 2961 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2962 | request.traffic_annotation = |
| 2963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2964 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2965 | TestNetLog log; |
| 2966 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2968 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2969 | MockWrite data_writes[] = { |
| 2970 | MockWrite(ASYNC, 0, |
| 2971 | "GET / HTTP/1.1\r\n" |
| 2972 | "Host: www.example.org\r\n" |
| 2973 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2975 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2976 | // be issuing -- the final header line contains the credentials. |
| 2977 | MockWrite(ASYNC, 6, |
| 2978 | "GET / HTTP/1.1\r\n" |
| 2979 | "Host: www.example.org\r\n" |
| 2980 | "Connection: keep-alive\r\n" |
| 2981 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2982 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2983 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2984 | MockRead data_reads[] = { |
| 2985 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2986 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2987 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2988 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2989 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2991 | // Lastly, the server responds with the actual content. |
| 2992 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2993 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2994 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2995 | MockRead(ASYNC, 10, "Hello"), |
| 2996 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2997 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2998 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2999 | data.set_busy_before_sync_reads(true); |
| 3000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3001 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3002 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3005 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3006 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3007 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3008 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3009 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3010 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3012 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3013 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3014 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3015 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3016 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3018 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3019 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3020 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3022 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3023 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3024 | TestLoadTimingReused(load_timing_info2); |
| 3025 | // The load timing after restart should have the same socket ID, and times |
| 3026 | // those of the first load timing. |
| 3027 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3028 | load_timing_info2.send_start); |
| 3029 | 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] | 3030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3031 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3032 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3033 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3034 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3035 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3036 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3037 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3039 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3040 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3041 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3042 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3043 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3047 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3048 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3049 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3050 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3051 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3052 | request.traffic_annotation = |
| 3053 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3056 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3057 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3058 | MockWrite("GET / HTTP/1.1\r\n" |
| 3059 | "Host: www.example.org\r\n" |
| 3060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3062 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3063 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3064 | MockWrite("GET / HTTP/1.1\r\n" |
| 3065 | "Host: www.example.org\r\n" |
| 3066 | "Connection: keep-alive\r\n" |
| 3067 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3068 | }; |
| 3069 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3070 | MockRead data_reads1[] = { |
| 3071 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3072 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3073 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3074 | |
| 3075 | // Lastly, the server responds with the actual content. |
| 3076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3077 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3078 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3079 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3080 | }; |
| 3081 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3082 | // An incorrect reconnect would cause this to be read. |
| 3083 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3084 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3085 | }; |
| 3086 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3087 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3088 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3090 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3092 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3094 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3095 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3097 | |
| 3098 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3101 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3102 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3103 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3105 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3107 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3109 | |
| 3110 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3112 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3113 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3114 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3115 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3116 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3120 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3121 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3122 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3123 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3124 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3125 | request.traffic_annotation = |
| 3126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3129 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3130 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3131 | MockWrite("GET / HTTP/1.1\r\n" |
| 3132 | "Host: www.example.org\r\n" |
| 3133 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3135 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3136 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3137 | MockWrite("GET / HTTP/1.1\r\n" |
| 3138 | "Host: www.example.org\r\n" |
| 3139 | "Connection: keep-alive\r\n" |
| 3140 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3141 | }; |
| 3142 | |
| 3143 | // Respond with 5 kb of response body. |
| 3144 | std::string large_body_string("Unauthorized"); |
| 3145 | large_body_string.append(5 * 1024, ' '); |
| 3146 | large_body_string.append("\r\n"); |
| 3147 | |
| 3148 | MockRead data_reads1[] = { |
| 3149 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3150 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3151 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3152 | // 5134 = 12 + 5 * 1024 + 2 |
| 3153 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3154 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3155 | |
| 3156 | // Lastly, the server responds with the actual content. |
| 3157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3158 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3159 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3160 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3161 | }; |
| 3162 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3163 | // An incorrect reconnect would cause this to be read. |
| 3164 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3165 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3166 | }; |
| 3167 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3168 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3169 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3170 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3171 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3173 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3175 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3176 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3178 | |
| 3179 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3180 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3183 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3184 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3186 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3188 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3190 | |
| 3191 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3192 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3194 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3195 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3196 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3197 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3201 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3202 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3203 | HttpRequestInfo request; |
| 3204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3205 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3206 | request.traffic_annotation = |
| 3207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3208 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3210 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3211 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3212 | MockWrite( |
| 3213 | "GET / HTTP/1.1\r\n" |
| 3214 | "Host: www.example.org\r\n" |
| 3215 | "Connection: keep-alive\r\n\r\n"), |
| 3216 | // This simulates the seemingly successful write to a closed connection |
| 3217 | // if the bug is not fixed. |
| 3218 | MockWrite( |
| 3219 | "GET / HTTP/1.1\r\n" |
| 3220 | "Host: www.example.org\r\n" |
| 3221 | "Connection: keep-alive\r\n" |
| 3222 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3223 | }; |
| 3224 | |
| 3225 | MockRead data_reads1[] = { |
| 3226 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3227 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3228 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3229 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3230 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3231 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3232 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3233 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3234 | }; |
| 3235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3236 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3237 | // be issuing -- the final header line contains the credentials. |
| 3238 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3239 | MockWrite( |
| 3240 | "GET / HTTP/1.1\r\n" |
| 3241 | "Host: www.example.org\r\n" |
| 3242 | "Connection: keep-alive\r\n" |
| 3243 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3244 | }; |
| 3245 | |
| 3246 | // Lastly, the server responds with the actual content. |
| 3247 | MockRead data_reads2[] = { |
| 3248 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3249 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3250 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3251 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3252 | }; |
| 3253 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3254 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3255 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3256 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3257 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3259 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3262 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3264 | |
| 3265 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3268 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3269 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3270 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3271 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3272 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3274 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3276 | |
| 3277 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3278 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3280 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3281 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3282 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3283 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3284 | } |
| 3285 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3286 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3287 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3288 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3289 | HttpRequestInfo request; |
| 3290 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3291 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3292 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3293 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3294 | request.traffic_annotation = |
| 3295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3296 | |
| 3297 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3298 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3299 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3300 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3301 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3302 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3304 | |
| 3305 | // Since we have proxy, should try to establish tunnel. |
| 3306 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3307 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3308 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3309 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3310 | }; |
| 3311 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3312 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3313 | // connection. |
| 3314 | MockRead data_reads1[] = { |
| 3315 | // No credentials. |
| 3316 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3317 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3318 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3319 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3320 | // Since the first connection couldn't be reused, need to establish another |
| 3321 | // once given credentials. |
| 3322 | MockWrite data_writes2[] = { |
| 3323 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3324 | // be issuing -- the final header line contains the credentials. |
| 3325 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3326 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3327 | "Proxy-Connection: keep-alive\r\n" |
| 3328 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3329 | |
| 3330 | MockWrite("GET / HTTP/1.1\r\n" |
| 3331 | "Host: www.example.org\r\n" |
| 3332 | "Connection: keep-alive\r\n\r\n"), |
| 3333 | }; |
| 3334 | |
| 3335 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3336 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3337 | |
| 3338 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3339 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3340 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3341 | MockRead(SYNCHRONOUS, "hello"), |
| 3342 | }; |
| 3343 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3344 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3345 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3346 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3347 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3348 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3350 | |
| 3351 | TestCompletionCallback callback1; |
| 3352 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3353 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3354 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3355 | |
| 3356 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3358 | |
| 3359 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3360 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3361 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | log.GetEntries(&entries); |
| 3363 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3364 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3365 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3366 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3367 | entries, pos, |
| 3368 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3369 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
| 3371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3372 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3374 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3375 | EXPECT_EQ(407, response->headers->response_code()); |
| 3376 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3377 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
| 3379 | LoadTimingInfo load_timing_info; |
| 3380 | // CONNECT requests and responses are handled at the connect job level, so |
| 3381 | // the transaction does not yet have a connection. |
| 3382 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3383 | |
| 3384 | TestCompletionCallback callback2; |
| 3385 | |
| 3386 | rv = |
| 3387 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3389 | |
| 3390 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3391 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3392 | |
| 3393 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3394 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3395 | |
| 3396 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3397 | EXPECT_EQ(200, response->headers->response_code()); |
| 3398 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3399 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3400 | |
| 3401 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3402 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3403 | |
| 3404 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3405 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3406 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3407 | |
| 3408 | trans.reset(); |
| 3409 | session->CloseAllConnections(); |
| 3410 | } |
| 3411 | |
| 3412 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3413 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3414 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3415 | HttpRequestInfo request; |
| 3416 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3417 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3418 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3419 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3420 | request.traffic_annotation = |
| 3421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3422 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3423 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3424 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3425 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3426 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3427 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3428 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3430 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3431 | // Since we have proxy, should try to establish tunnel. |
| 3432 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3433 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3434 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3435 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3436 | }; |
| 3437 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3438 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3439 | // connection. |
| 3440 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3441 | // No credentials. |
| 3442 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3443 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3444 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3445 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3446 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3447 | MockWrite data_writes2[] = { |
| 3448 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3449 | // be issuing -- the final header line contains the credentials. |
| 3450 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3451 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3452 | "Proxy-Connection: keep-alive\r\n" |
| 3453 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3454 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3455 | MockWrite("GET / HTTP/1.1\r\n" |
| 3456 | "Host: www.example.org\r\n" |
| 3457 | "Connection: keep-alive\r\n\r\n"), |
| 3458 | }; |
| 3459 | |
| 3460 | MockRead data_reads2[] = { |
| 3461 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3462 | |
| 3463 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3464 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3465 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3466 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | }; |
| 3468 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3469 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3471 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3472 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3473 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3476 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3477 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3478 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3479 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3480 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3481 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3483 | |
| 3484 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3485 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3486 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3487 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3488 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3489 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3490 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3491 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3492 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3493 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3494 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3495 | |
| 3496 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3497 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3498 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3499 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3500 | EXPECT_EQ(407, response->headers->response_code()); |
| 3501 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3502 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3503 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3504 | LoadTimingInfo load_timing_info; |
| 3505 | // CONNECT requests and responses are handled at the connect job level, so |
| 3506 | // the transaction does not yet have a connection. |
| 3507 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3508 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3509 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3510 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3511 | rv = trans->RestartWithAuth( |
| 3512 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3514 | |
| 3515 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3517 | |
| 3518 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3519 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3520 | |
| 3521 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3522 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3523 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3524 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3525 | |
| 3526 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3527 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3528 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3529 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3530 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3531 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3532 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3533 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3534 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3535 | } |
| 3536 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3537 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3538 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3539 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3540 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3541 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3542 | // reused. See http://crbug.com/544255. |
| 3543 | for (int i = 0; i < 2; ++i) { |
| 3544 | HttpRequestInfo request; |
| 3545 | request.method = "GET"; |
| 3546 | request.url = GURL("https://www.example.org/"); |
| 3547 | // Ensure that proxy authentication is attempted even |
| 3548 | // when the no authentication data flag is set. |
| 3549 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3550 | request.traffic_annotation = |
| 3551 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3552 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3553 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3554 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3555 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3556 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | BoundTestNetLog log; |
| 3558 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3562 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3563 | // Since we have proxy, should try to establish tunnel. |
| 3564 | MockWrite data_writes1[] = { |
| 3565 | MockWrite(ASYNC, 0, |
| 3566 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3567 | "Host: www.example.org:443\r\n" |
| 3568 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3570 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3571 | // be issuing -- the final header line contains the credentials. |
| 3572 | MockWrite(ASYNC, 3, |
| 3573 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3574 | "Host: www.example.org:443\r\n" |
| 3575 | "Proxy-Connection: keep-alive\r\n" |
| 3576 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3577 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3578 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3579 | // The proxy responds to the connect with a 407, using a persistent |
| 3580 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3581 | MockRead data_reads1[] = { |
| 3582 | // No credentials. |
| 3583 | MockRead(ASYNC, 1, |
| 3584 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3585 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3586 | "Proxy-Connection: keep-alive\r\n" |
| 3587 | "Content-Length: 10\r\n\r\n"), |
| 3588 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | // Wrong credentials (wrong password). |
| 3591 | MockRead(ASYNC, 4, |
| 3592 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3593 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3594 | "Proxy-Connection: keep-alive\r\n" |
| 3595 | "Content-Length: 10\r\n\r\n"), |
| 3596 | // No response body because the test stops reading here. |
| 3597 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3598 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3599 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3600 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3601 | data1.set_busy_before_sync_reads(true); |
| 3602 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3603 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3606 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3607 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3608 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3609 | TestNetLogEntry::List entries; |
| 3610 | log.GetEntries(&entries); |
| 3611 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3612 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3613 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3614 | ExpectLogContainsSomewhere( |
| 3615 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3616 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3617 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
| 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
| 3624 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3625 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3626 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3627 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3629 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3630 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3631 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3632 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3633 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3635 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3636 | ASSERT_TRUE(response); |
| 3637 | ASSERT_TRUE(response->headers); |
| 3638 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3639 | EXPECT_EQ(407, response->headers->response_code()); |
| 3640 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3641 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3642 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3643 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3644 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3645 | // out of scope. |
| 3646 | session->CloseAllConnections(); |
| 3647 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3651 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3652 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3653 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3654 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3655 | // reused. See http://crbug.com/544255. |
| 3656 | for (int i = 0; i < 2; ++i) { |
| 3657 | HttpRequestInfo request; |
| 3658 | request.method = "GET"; |
| 3659 | request.url = GURL("https://www.example.org/"); |
| 3660 | // Ensure that proxy authentication is attempted even |
| 3661 | // when the no authentication data flag is set. |
| 3662 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3663 | request.traffic_annotation = |
| 3664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3665 | |
| 3666 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3667 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3668 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3669 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3670 | BoundTestNetLog log; |
| 3671 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3675 | |
| 3676 | // Since we have proxy, should try to establish tunnel. |
| 3677 | MockWrite data_writes1[] = { |
| 3678 | MockWrite(ASYNC, 0, |
| 3679 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3680 | "Host: www.example.org:443\r\n" |
| 3681 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3683 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3684 | // be issuing -- the final header line contains the credentials. |
| 3685 | MockWrite(ASYNC, 3, |
| 3686 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3687 | "Host: www.example.org:443\r\n" |
| 3688 | "Proxy-Connection: keep-alive\r\n" |
| 3689 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3690 | }; |
| 3691 | |
| 3692 | // The proxy responds to the connect with a 407, using a persistent |
| 3693 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3694 | MockRead data_reads1[] = { |
| 3695 | // No credentials. |
| 3696 | MockRead(ASYNC, 1, |
| 3697 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3698 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3699 | "Content-Length: 10\r\n\r\n"), |
| 3700 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3701 | |
| 3702 | // Wrong credentials (wrong password). |
| 3703 | MockRead(ASYNC, 4, |
| 3704 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3705 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3706 | "Content-Length: 10\r\n\r\n"), |
| 3707 | // No response body because the test stops reading here. |
| 3708 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3709 | }; |
| 3710 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3711 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3712 | data1.set_busy_before_sync_reads(true); |
| 3713 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3714 | |
| 3715 | TestCompletionCallback callback1; |
| 3716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3717 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3718 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3719 | |
| 3720 | TestNetLogEntry::List entries; |
| 3721 | log.GetEntries(&entries); |
| 3722 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3723 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3724 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3725 | ExpectLogContainsSomewhere( |
| 3726 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3727 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3728 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3730 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3731 | ASSERT_TRUE(response); |
| 3732 | ASSERT_TRUE(response->headers); |
| 3733 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3734 | EXPECT_EQ(407, response->headers->response_code()); |
| 3735 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3736 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3737 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3738 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3739 | |
| 3740 | TestCompletionCallback callback2; |
| 3741 | |
| 3742 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3743 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3744 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3745 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3747 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3748 | ASSERT_TRUE(response); |
| 3749 | ASSERT_TRUE(response->headers); |
| 3750 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3751 | EXPECT_EQ(407, response->headers->response_code()); |
| 3752 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3753 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3754 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3755 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3756 | |
| 3757 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3758 | // out of scope. |
| 3759 | session->CloseAllConnections(); |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3764 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3765 | // the case the server sends extra data on the original socket, so it can't be |
| 3766 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3767 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3768 | HttpRequestInfo request; |
| 3769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3770 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3771 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3772 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3773 | request.traffic_annotation = |
| 3774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3775 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3776 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3777 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3778 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3779 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3780 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3781 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3783 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3784 | // Since we have proxy, should try to establish tunnel. |
| 3785 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3786 | MockWrite(ASYNC, 0, |
| 3787 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3788 | "Host: www.example.org:443\r\n" |
| 3789 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3790 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3791 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3792 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3793 | // extra data, so the socket cannot be reused. |
| 3794 | MockRead data_reads1[] = { |
| 3795 | // No credentials. |
| 3796 | MockRead(ASYNC, 1, |
| 3797 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3798 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3799 | "Content-Length: 10\r\n\r\n"), |
| 3800 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3801 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3802 | }; |
| 3803 | |
| 3804 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3805 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3806 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3807 | MockWrite(ASYNC, 0, |
| 3808 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3809 | "Host: www.example.org:443\r\n" |
| 3810 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3811 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3812 | |
| 3813 | MockWrite(ASYNC, 2, |
| 3814 | "GET / HTTP/1.1\r\n" |
| 3815 | "Host: www.example.org\r\n" |
| 3816 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3817 | }; |
| 3818 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3819 | MockRead data_reads2[] = { |
| 3820 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3821 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3822 | MockRead(ASYNC, 3, |
| 3823 | "HTTP/1.1 200 OK\r\n" |
| 3824 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3825 | "Content-Length: 5\r\n\r\n"), |
| 3826 | // No response body because the test stops reading here. |
| 3827 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3828 | }; |
| 3829 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3830 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3831 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3832 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3833 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3834 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3835 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3836 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3838 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3839 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3840 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3842 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3843 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3844 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3846 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3847 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3848 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3849 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3850 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3851 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3852 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3853 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3854 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3855 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3856 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3857 | ASSERT_TRUE(response); |
| 3858 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3859 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3860 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3861 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3862 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3863 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3864 | LoadTimingInfo load_timing_info; |
| 3865 | // CONNECT requests and responses are handled at the connect job level, so |
| 3866 | // the transaction does not yet have a connection. |
| 3867 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3869 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3870 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3871 | rv = |
| 3872 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3873 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3874 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3875 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3876 | EXPECT_EQ(200, response->headers->response_code()); |
| 3877 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3878 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3879 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3880 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3881 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3882 | |
| 3883 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3884 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3885 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3886 | |
| 3887 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3888 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3889 | } |
| 3890 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3891 | // Test the case a proxy closes a socket while the challenge body is being |
| 3892 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3893 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3894 | HttpRequestInfo request; |
| 3895 | request.method = "GET"; |
| 3896 | request.url = GURL("https://www.example.org/"); |
| 3897 | // Ensure that proxy authentication is attempted even |
| 3898 | // when the no authentication data flag is set. |
| 3899 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3900 | request.traffic_annotation = |
| 3901 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3902 | |
| 3903 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3904 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3905 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3906 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3909 | |
| 3910 | // Since we have proxy, should try to establish tunnel. |
| 3911 | MockWrite data_writes1[] = { |
| 3912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3913 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3914 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3915 | }; |
| 3916 | |
| 3917 | // The proxy responds to the connect with a 407, using a persistent |
| 3918 | // connection. |
| 3919 | MockRead data_reads1[] = { |
| 3920 | // No credentials. |
| 3921 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3922 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3923 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3924 | // Server hands up in the middle of the body. |
| 3925 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3926 | }; |
| 3927 | |
| 3928 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3929 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3930 | // be issuing -- the final header line contains the credentials. |
| 3931 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3932 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3933 | "Proxy-Connection: keep-alive\r\n" |
| 3934 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3935 | |
| 3936 | MockWrite("GET / HTTP/1.1\r\n" |
| 3937 | "Host: www.example.org\r\n" |
| 3938 | "Connection: keep-alive\r\n\r\n"), |
| 3939 | }; |
| 3940 | |
| 3941 | MockRead data_reads2[] = { |
| 3942 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3943 | |
| 3944 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3945 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3946 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3947 | MockRead(SYNCHRONOUS, "hello"), |
| 3948 | }; |
| 3949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3950 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3951 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3952 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3953 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3954 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3956 | |
| 3957 | TestCompletionCallback callback; |
| 3958 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3959 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3960 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3963 | ASSERT_TRUE(response); |
| 3964 | ASSERT_TRUE(response->headers); |
| 3965 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3966 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3967 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3969 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3970 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3972 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3973 | ASSERT_TRUE(response); |
| 3974 | ASSERT_TRUE(response->headers); |
| 3975 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3976 | EXPECT_EQ(200, response->headers->response_code()); |
| 3977 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3978 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3979 | EXPECT_EQ("hello", body); |
| 3980 | } |
| 3981 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3982 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3983 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3984 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3985 | HttpRequestInfo request; |
| 3986 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3987 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3988 | request.traffic_annotation = |
| 3989 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3990 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3991 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3992 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3993 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3998 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3999 | // Since we have proxy, should try to establish tunnel. |
| 4000 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4001 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4002 | "Host: www.example.org:443\r\n" |
| 4003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4004 | }; |
| 4005 | |
| 4006 | // The proxy responds to the connect with a 407. |
| 4007 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4008 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4009 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4010 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4011 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4012 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | }; |
| 4014 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4015 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4016 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4017 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4018 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4019 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4020 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4022 | |
| 4023 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4024 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4026 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4027 | ASSERT_TRUE(response); |
| 4028 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4029 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4030 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4031 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4032 | |
| 4033 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4034 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4035 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4036 | |
| 4037 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4038 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4039 | } |
| 4040 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4041 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4042 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4043 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4044 | HttpRequestInfo request; |
| 4045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4046 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4047 | request.traffic_annotation = |
| 4048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4049 | |
| 4050 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4051 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4052 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4056 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4057 | |
| 4058 | // Since we have proxy, should try to establish tunnel. |
| 4059 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4060 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4061 | "Host: www.example.org:443\r\n" |
| 4062 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4063 | }; |
| 4064 | |
| 4065 | // The proxy responds to the connect with a 407. |
| 4066 | MockRead data_reads[] = { |
| 4067 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4068 | MockRead("X-Foo: bar\r\n"), |
| 4069 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4070 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4071 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4072 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4073 | }; |
| 4074 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4075 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4077 | |
| 4078 | TestCompletionCallback callback; |
| 4079 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4080 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4082 | |
| 4083 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4084 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4086 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4087 | ASSERT_TRUE(response); |
| 4088 | ASSERT_TRUE(response->headers); |
| 4089 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4090 | EXPECT_EQ(407, response->headers->response_code()); |
| 4091 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4092 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4093 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4094 | |
| 4095 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4096 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4097 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4098 | |
| 4099 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4100 | session->CloseAllConnections(); |
| 4101 | } |
| 4102 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4103 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4104 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4105 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4106 | HttpRequestInfo request; |
| 4107 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4108 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4109 | request.traffic_annotation = |
| 4110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4111 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4112 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4115 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4116 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4117 | MockWrite( |
| 4118 | "GET / HTTP/1.1\r\n" |
| 4119 | "Host: www.example.org\r\n" |
| 4120 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4121 | }; |
| 4122 | |
| 4123 | MockRead data_reads1[] = { |
| 4124 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4125 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4126 | // Large content-length -- won't matter, as connection will be reset. |
| 4127 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4128 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4129 | }; |
| 4130 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4131 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4132 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4134 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4135 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4136 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4138 | |
| 4139 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4140 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4141 | } |
| 4142 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4143 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4144 | // through a non-authenticating proxy. The request should fail with |
| 4145 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4146 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4147 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4148 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4149 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4150 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4151 | HttpRequestInfo request; |
| 4152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4153 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4154 | request.traffic_annotation = |
| 4155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4156 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4157 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4158 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4159 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4160 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4162 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4163 | // Since we have proxy, should try to establish tunnel. |
| 4164 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4165 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4166 | "Host: www.example.org:443\r\n" |
| 4167 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4169 | MockWrite("GET / HTTP/1.1\r\n" |
| 4170 | "Host: www.example.org\r\n" |
| 4171 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4172 | }; |
| 4173 | |
| 4174 | MockRead data_reads1[] = { |
| 4175 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4176 | |
| 4177 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4178 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4179 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4181 | }; |
| 4182 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4183 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4184 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4185 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4188 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4190 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4192 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4194 | |
| 4195 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4196 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4197 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4198 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4199 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4200 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4201 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4202 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4203 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4204 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4205 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4206 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4207 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4209 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4210 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4211 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4212 | HttpRequestInfo request; |
| 4213 | request.method = "GET"; |
| 4214 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4215 | request.traffic_annotation = |
| 4216 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4217 | |
| 4218 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4219 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4220 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4221 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4222 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4223 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4225 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4226 | mock_handler->set_allows_default_credentials(true); |
| 4227 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4228 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4229 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4230 | |
| 4231 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4232 | NetLog net_log; |
| 4233 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4234 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4235 | |
| 4236 | // Since we have proxy, should try to establish tunnel. |
| 4237 | MockWrite data_writes1[] = { |
| 4238 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4239 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4240 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4241 | }; |
| 4242 | |
| 4243 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4244 | // connection. |
| 4245 | MockRead data_reads1[] = { |
| 4246 | // No credentials. |
| 4247 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4248 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4249 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4250 | }; |
| 4251 | |
| 4252 | // Since the first connection couldn't be reused, need to establish another |
| 4253 | // once given credentials. |
| 4254 | MockWrite data_writes2[] = { |
| 4255 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4256 | // be issuing -- the final header line contains the credentials. |
| 4257 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4258 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4259 | "Proxy-Connection: keep-alive\r\n" |
| 4260 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4261 | |
| 4262 | MockWrite("GET / HTTP/1.1\r\n" |
| 4263 | "Host: www.example.org\r\n" |
| 4264 | "Connection: keep-alive\r\n\r\n"), |
| 4265 | }; |
| 4266 | |
| 4267 | MockRead data_reads2[] = { |
| 4268 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4269 | |
| 4270 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4271 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4272 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4273 | MockRead(SYNCHRONOUS, "hello"), |
| 4274 | }; |
| 4275 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4276 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4277 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4278 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4279 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4280 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4282 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4283 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4284 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4285 | |
| 4286 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4287 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4288 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4289 | |
| 4290 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4291 | ASSERT_TRUE(response); |
| 4292 | ASSERT_TRUE(response->headers); |
| 4293 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4294 | EXPECT_EQ(407, response->headers->response_code()); |
| 4295 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4296 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4297 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4298 | |
| 4299 | LoadTimingInfo load_timing_info; |
| 4300 | // CONNECT requests and responses are handled at the connect job level, so |
| 4301 | // the transaction does not yet have a connection. |
| 4302 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4303 | |
| 4304 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4305 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | response = trans->GetResponseInfo(); |
| 4307 | ASSERT_TRUE(response); |
| 4308 | ASSERT_TRUE(response->headers); |
| 4309 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4310 | EXPECT_EQ(200, response->headers->response_code()); |
| 4311 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4312 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4313 | |
| 4314 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4315 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | |
| 4317 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4318 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4319 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4320 | |
| 4321 | trans.reset(); |
| 4322 | session->CloseAllConnections(); |
| 4323 | } |
| 4324 | |
| 4325 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4326 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4327 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4328 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4329 | HttpRequestInfo request; |
| 4330 | request.method = "GET"; |
| 4331 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4332 | request.traffic_annotation = |
| 4333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | |
| 4335 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4336 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4337 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4338 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4339 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4340 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4341 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4342 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4343 | mock_handler->set_allows_default_credentials(true); |
| 4344 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4345 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4346 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4347 | |
| 4348 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4349 | NetLog net_log; |
| 4350 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4351 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4352 | |
| 4353 | // Should try to establish tunnel. |
| 4354 | MockWrite data_writes1[] = { |
| 4355 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4356 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4357 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4358 | |
| 4359 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4360 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4361 | "Proxy-Connection: keep-alive\r\n" |
| 4362 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4363 | }; |
| 4364 | |
| 4365 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4366 | // connection. |
| 4367 | MockRead data_reads1[] = { |
| 4368 | // No credentials. |
| 4369 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4370 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4371 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4372 | }; |
| 4373 | |
| 4374 | // Since the first connection was closed, need to establish another once given |
| 4375 | // credentials. |
| 4376 | MockWrite data_writes2[] = { |
| 4377 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4378 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4379 | "Proxy-Connection: keep-alive\r\n" |
| 4380 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4381 | |
| 4382 | MockWrite("GET / HTTP/1.1\r\n" |
| 4383 | "Host: www.example.org\r\n" |
| 4384 | "Connection: keep-alive\r\n\r\n"), |
| 4385 | }; |
| 4386 | |
| 4387 | MockRead data_reads2[] = { |
| 4388 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4389 | |
| 4390 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4392 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4393 | MockRead(SYNCHRONOUS, "hello"), |
| 4394 | }; |
| 4395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4396 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4397 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4398 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4399 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4400 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4402 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4403 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4404 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4405 | |
| 4406 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4407 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4408 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4409 | |
| 4410 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4411 | ASSERT_TRUE(response); |
| 4412 | ASSERT_TRUE(response->headers); |
| 4413 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4414 | EXPECT_EQ(407, response->headers->response_code()); |
| 4415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4416 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4417 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4418 | |
| 4419 | LoadTimingInfo load_timing_info; |
| 4420 | // CONNECT requests and responses are handled at the connect job level, so |
| 4421 | // the transaction does not yet have a connection. |
| 4422 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4423 | |
| 4424 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4425 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4426 | |
| 4427 | response = trans->GetResponseInfo(); |
| 4428 | ASSERT_TRUE(response); |
| 4429 | ASSERT_TRUE(response->headers); |
| 4430 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4431 | EXPECT_EQ(200, response->headers->response_code()); |
| 4432 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4433 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4434 | |
| 4435 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4436 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4437 | |
| 4438 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4439 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4440 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4441 | |
| 4442 | trans.reset(); |
| 4443 | session->CloseAllConnections(); |
| 4444 | } |
| 4445 | |
| 4446 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4447 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4448 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4449 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4450 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4451 | HttpRequestInfo request; |
| 4452 | request.method = "GET"; |
| 4453 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4454 | request.traffic_annotation = |
| 4455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4456 | |
| 4457 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4458 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4459 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4460 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4461 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4462 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4463 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4464 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4465 | mock_handler->set_allows_default_credentials(true); |
| 4466 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4467 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4468 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4469 | |
| 4470 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4471 | NetLog net_log; |
| 4472 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4473 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4474 | |
| 4475 | // Should try to establish tunnel. |
| 4476 | MockWrite data_writes1[] = { |
| 4477 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4478 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4479 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4480 | |
| 4481 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4482 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4483 | "Proxy-Connection: keep-alive\r\n" |
| 4484 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4485 | }; |
| 4486 | |
| 4487 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4488 | // second request is sent. |
| 4489 | MockRead data_reads1[] = { |
| 4490 | // No credentials. |
| 4491 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4492 | MockRead("Content-Length: 0\r\n"), |
| 4493 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4494 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4495 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4496 | }; |
| 4497 | |
| 4498 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4499 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4500 | // request. |
| 4501 | MockWrite data_writes2[] = { |
| 4502 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4503 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4504 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4505 | }; |
| 4506 | |
| 4507 | // The proxy, having had more than enough of us, just hangs up. |
| 4508 | MockRead data_reads2[] = { |
| 4509 | // No credentials. |
| 4510 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4511 | }; |
| 4512 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4513 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4515 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4516 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4517 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4518 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4519 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4520 | |
| 4521 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4522 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4523 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4524 | |
| 4525 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4526 | ASSERT_TRUE(response); |
| 4527 | ASSERT_TRUE(response->headers); |
| 4528 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4529 | EXPECT_EQ(407, response->headers->response_code()); |
| 4530 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4531 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4532 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4533 | |
| 4534 | LoadTimingInfo load_timing_info; |
| 4535 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4536 | |
| 4537 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4538 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4539 | |
| 4540 | trans.reset(); |
| 4541 | session->CloseAllConnections(); |
| 4542 | } |
| 4543 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4544 | // This test exercises an odd edge case where the proxy closes the connection |
| 4545 | // after the authentication handshake is complete. Presumably this technique is |
| 4546 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4547 | // succeeds, but the user is not authorized to connect to the destination |
| 4548 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4549 | // site. |
| 4550 | TEST_F(HttpNetworkTransactionTest, |
| 4551 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4552 | HttpRequestInfo request; |
| 4553 | request.method = "GET"; |
| 4554 | request.url = GURL("https://www.example.org/"); |
| 4555 | request.traffic_annotation = |
| 4556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4557 | |
| 4558 | // Configure against proxy server "myproxy:70". |
| 4559 | session_deps_.proxy_resolution_service = |
| 4560 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4561 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4562 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4563 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4564 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4565 | |
| 4566 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4567 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4568 | // was a real network error. |
| 4569 | // |
| 4570 | // The handlers support both default and explicit credentials. The retry |
| 4571 | // mentioned above should be able to reuse the default identity. Thus there |
| 4572 | // should never be a need to prompt for explicit credentials. |
| 4573 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4574 | mock_handler->set_allows_default_credentials(true); |
| 4575 | mock_handler->set_allows_explicit_credentials(true); |
| 4576 | mock_handler->set_connection_based(true); |
| 4577 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4578 | HttpAuth::AUTH_PROXY); |
| 4579 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4580 | mock_handler->set_allows_default_credentials(true); |
| 4581 | mock_handler->set_allows_explicit_credentials(true); |
| 4582 | mock_handler->set_connection_based(true); |
| 4583 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4584 | HttpAuth::AUTH_PROXY); |
| 4585 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4586 | |
| 4587 | NetLog net_log; |
| 4588 | session_deps_.net_log = &net_log; |
| 4589 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4590 | |
| 4591 | // Data for both sockets. |
| 4592 | // |
| 4593 | // Writes are for the tunnel establishment attempts and the |
| 4594 | // authentication handshake. |
| 4595 | MockWrite data_writes1[] = { |
| 4596 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4597 | "Host: www.example.org:443\r\n" |
| 4598 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4599 | |
| 4600 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4601 | "Host: www.example.org:443\r\n" |
| 4602 | "Proxy-Connection: keep-alive\r\n" |
| 4603 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4604 | |
| 4605 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4606 | "Host: www.example.org:443\r\n" |
| 4607 | "Proxy-Connection: keep-alive\r\n" |
| 4608 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4609 | }; |
| 4610 | |
| 4611 | // The server side of the authentication handshake. Note that the response to |
| 4612 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4613 | MockRead data_reads1[] = { |
| 4614 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4615 | MockRead("Content-Length: 0\r\n"), |
| 4616 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4617 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4618 | |
| 4619 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4620 | MockRead("Content-Length: 0\r\n"), |
| 4621 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4622 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4623 | |
| 4624 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4625 | }; |
| 4626 | |
| 4627 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4628 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4629 | |
| 4630 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4631 | // first attempt. |
| 4632 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4633 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4634 | |
| 4635 | auto trans = |
| 4636 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4637 | |
| 4638 | TestCompletionCallback callback; |
| 4639 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4640 | |
| 4641 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4642 | // stack. |
| 4643 | for (int i = 0; i < 4; ++i) { |
| 4644 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4645 | |
| 4646 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4647 | ASSERT_TRUE(response); |
| 4648 | ASSERT_TRUE(response->headers); |
| 4649 | EXPECT_EQ(407, response->headers->response_code()); |
| 4650 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4651 | |
| 4652 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4653 | } |
| 4654 | |
| 4655 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4656 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4657 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4658 | // being the first number, be reached, then lobbest thou thy |
| 4659 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4660 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4661 | |
| 4662 | trans.reset(); |
| 4663 | session->CloseAllConnections(); |
| 4664 | } |
| 4665 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4666 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4667 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4668 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4669 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4670 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4671 | HttpRequestInfo request; |
| 4672 | request.method = "GET"; |
| 4673 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4674 | request.traffic_annotation = |
| 4675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4676 | |
| 4677 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4678 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4679 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4680 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4681 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4682 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4683 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4684 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4685 | mock_handler->set_allows_default_credentials(true); |
| 4686 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4687 | HttpAuth::AUTH_PROXY); |
| 4688 | // Add another handler for the second challenge. It supports default |
| 4689 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4690 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4691 | mock_handler->set_allows_default_credentials(true); |
| 4692 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4693 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4694 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4695 | |
| 4696 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4697 | NetLog net_log; |
| 4698 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4699 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4700 | |
| 4701 | // Should try to establish tunnel. |
| 4702 | MockWrite data_writes1[] = { |
| 4703 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4704 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4705 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4706 | }; |
| 4707 | |
| 4708 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4709 | // connection. |
| 4710 | MockRead data_reads1[] = { |
| 4711 | // No credentials. |
| 4712 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4713 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4714 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4715 | }; |
| 4716 | |
| 4717 | // Since the first connection was closed, need to establish another once given |
| 4718 | // credentials. |
| 4719 | MockWrite data_writes2[] = { |
| 4720 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4721 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4722 | "Proxy-Connection: keep-alive\r\n" |
| 4723 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4724 | }; |
| 4725 | |
| 4726 | MockRead data_reads2[] = { |
| 4727 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4728 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4729 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4730 | }; |
| 4731 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4732 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4733 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4734 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4735 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4736 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4738 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4739 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4740 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4741 | |
| 4742 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4743 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4744 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4745 | |
| 4746 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4747 | ASSERT_TRUE(response); |
| 4748 | ASSERT_TRUE(response->headers); |
| 4749 | EXPECT_EQ(407, response->headers->response_code()); |
| 4750 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4751 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4752 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4753 | |
| 4754 | LoadTimingInfo load_timing_info; |
| 4755 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4756 | |
| 4757 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4758 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4759 | response = trans->GetResponseInfo(); |
| 4760 | ASSERT_TRUE(response); |
| 4761 | ASSERT_TRUE(response->headers); |
| 4762 | EXPECT_EQ(407, response->headers->response_code()); |
| 4763 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4764 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4765 | |
| 4766 | trans.reset(); |
| 4767 | session->CloseAllConnections(); |
| 4768 | } |
| 4769 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4770 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4771 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4772 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4773 | // authentication handshake can continue with the same scheme but with a |
| 4774 | // different identity. |
| 4775 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4776 | HttpRequestInfo request; |
| 4777 | request.method = "GET"; |
| 4778 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4779 | request.traffic_annotation = |
| 4780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4781 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4782 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4783 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4784 | |
| 4785 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4786 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4787 | mock_handler->set_allows_default_credentials(true); |
| 4788 | mock_handler->set_allows_explicit_credentials(true); |
| 4789 | mock_handler->set_connection_based(true); |
| 4790 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4791 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4792 | HttpAuth::AUTH_SERVER); |
| 4793 | |
| 4794 | // Add another handler for the second challenge. It supports default |
| 4795 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4796 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4797 | mock_handler->set_allows_default_credentials(true); |
| 4798 | mock_handler->set_allows_explicit_credentials(true); |
| 4799 | mock_handler->set_connection_based(true); |
| 4800 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4801 | HttpAuth::AUTH_SERVER); |
| 4802 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4803 | |
| 4804 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4805 | |
| 4806 | MockWrite data_writes1[] = { |
| 4807 | MockWrite("GET / HTTP/1.1\r\n" |
| 4808 | "Host: www.example.org\r\n" |
| 4809 | "Connection: keep-alive\r\n\r\n"), |
| 4810 | }; |
| 4811 | |
| 4812 | MockRead data_reads1[] = { |
| 4813 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4814 | "WWW-Authenticate: Mock\r\n" |
| 4815 | "Connection: keep-alive\r\n\r\n"), |
| 4816 | }; |
| 4817 | |
| 4818 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4819 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4820 | // transaction procceds without an authorization header. |
| 4821 | MockWrite data_writes2[] = { |
| 4822 | MockWrite("GET / HTTP/1.1\r\n" |
| 4823 | "Host: www.example.org\r\n" |
| 4824 | "Connection: keep-alive\r\n\r\n"), |
| 4825 | }; |
| 4826 | |
| 4827 | MockRead data_reads2[] = { |
| 4828 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4829 | "WWW-Authenticate: Mock\r\n" |
| 4830 | "Connection: keep-alive\r\n\r\n"), |
| 4831 | }; |
| 4832 | |
| 4833 | MockWrite data_writes3[] = { |
| 4834 | MockWrite("GET / HTTP/1.1\r\n" |
| 4835 | "Host: www.example.org\r\n" |
| 4836 | "Connection: keep-alive\r\n" |
| 4837 | "Authorization: auth_token\r\n\r\n"), |
| 4838 | }; |
| 4839 | |
| 4840 | MockRead data_reads3[] = { |
| 4841 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4842 | "Content-Length: 5\r\n" |
| 4843 | "Content-Type: text/plain\r\n" |
| 4844 | "Connection: keep-alive\r\n\r\n" |
| 4845 | "Hello"), |
| 4846 | }; |
| 4847 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4848 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4849 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4850 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4851 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4852 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4854 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4855 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4856 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4857 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4858 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4859 | |
| 4860 | TestCompletionCallback callback; |
| 4861 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4862 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4863 | |
| 4864 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4865 | ASSERT_TRUE(response); |
| 4866 | ASSERT_TRUE(response->headers); |
| 4867 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4868 | |
| 4869 | // The following three tests assert that an authentication challenge was |
| 4870 | // received and that the stack is ready to respond to the challenge using |
| 4871 | // ambient credentials. |
| 4872 | EXPECT_EQ(401, response->headers->response_code()); |
| 4873 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4874 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4875 | |
| 4876 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4877 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4878 | response = trans->GetResponseInfo(); |
| 4879 | ASSERT_TRUE(response); |
| 4880 | ASSERT_TRUE(response->headers); |
| 4881 | |
| 4882 | // The following three tests assert that an authentication challenge was |
| 4883 | // received and that the stack needs explicit credentials before it is ready |
| 4884 | // to respond to the challenge. |
| 4885 | EXPECT_EQ(401, response->headers->response_code()); |
| 4886 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4887 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4888 | |
| 4889 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4890 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4891 | response = trans->GetResponseInfo(); |
| 4892 | ASSERT_TRUE(response); |
| 4893 | ASSERT_TRUE(response->headers); |
| 4894 | EXPECT_EQ(200, response->headers->response_code()); |
| 4895 | |
| 4896 | trans.reset(); |
| 4897 | session->CloseAllConnections(); |
| 4898 | } |
| 4899 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4900 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4901 | // schemes, based on the path of the URL being requests. |
| 4902 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4903 | public: |
| 4904 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4905 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4906 | |
| 4907 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4908 | |
| 4909 | static HostPortPair ProxyHostPortPair() { |
| 4910 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4911 | } |
| 4912 | |
| 4913 | // ProxyResolver implementation. |
| 4914 | int GetProxyForURL(const GURL& url, |
| 4915 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4916 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4917 | std::unique_ptr<Request>* request, |
| 4918 | const NetLogWithSource& /*net_log*/) override { |
| 4919 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4920 | results->set_traffic_annotation( |
| 4921 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4922 | if (url.path() == "/socks4") { |
| 4923 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4924 | return OK; |
| 4925 | } |
| 4926 | if (url.path() == "/socks5") { |
| 4927 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4928 | return OK; |
| 4929 | } |
| 4930 | if (url.path() == "/http") { |
| 4931 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4932 | return OK; |
| 4933 | } |
| 4934 | if (url.path() == "/https") { |
| 4935 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4936 | return OK; |
| 4937 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4938 | if (url.path() == "/https_trusted") { |
| 4939 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4940 | ProxyHostPortPair(), |
| 4941 | true /* is_trusted_proxy */)); |
| 4942 | return OK; |
| 4943 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4944 | NOTREACHED(); |
| 4945 | return ERR_NOT_IMPLEMENTED; |
| 4946 | } |
| 4947 | |
| 4948 | private: |
| 4949 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4950 | }; |
| 4951 | |
| 4952 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4953 | : public ProxyResolverFactory { |
| 4954 | public: |
| 4955 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4956 | : ProxyResolverFactory(false) {} |
| 4957 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4958 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4959 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4960 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4961 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4962 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4963 | return OK; |
| 4964 | } |
| 4965 | |
| 4966 | private: |
| 4967 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4968 | }; |
| 4969 | |
| 4970 | // 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] | 4971 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4972 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4973 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4974 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4975 | session_deps_.proxy_resolution_service = |
| 4976 | std::make_unique<ProxyResolutionService>( |
| 4977 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4978 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4979 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4980 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4981 | |
| 4982 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4983 | |
| 4984 | MockWrite socks_writes[] = { |
| 4985 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4986 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4987 | MockWrite(SYNCHRONOUS, |
| 4988 | "GET /socks4 HTTP/1.1\r\n" |
| 4989 | "Host: test\r\n" |
| 4990 | "Connection: keep-alive\r\n\r\n"), |
| 4991 | }; |
| 4992 | MockRead socks_reads[] = { |
| 4993 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4994 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4995 | "Connection: keep-alive\r\n" |
| 4996 | "Content-Length: 15\r\n\r\n" |
| 4997 | "SOCKS4 Response"), |
| 4998 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4999 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5000 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 5001 | |
| 5002 | const char kSOCKS5Request[] = { |
| 5003 | 0x05, // Version |
| 5004 | 0x01, // Command (CONNECT) |
| 5005 | 0x00, // Reserved |
| 5006 | 0x03, // Address type (DOMAINNAME) |
| 5007 | 0x04, // Length of domain (4) |
| 5008 | 't', 'e', 's', 't', // Domain string |
| 5009 | 0x00, 0x50, // 16-bit port (80) |
| 5010 | }; |
| 5011 | MockWrite socks5_writes[] = { |
| 5012 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5013 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5014 | MockWrite(SYNCHRONOUS, |
| 5015 | "GET /socks5 HTTP/1.1\r\n" |
| 5016 | "Host: test\r\n" |
| 5017 | "Connection: keep-alive\r\n\r\n"), |
| 5018 | }; |
| 5019 | MockRead socks5_reads[] = { |
| 5020 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5021 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5022 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5023 | "Connection: keep-alive\r\n" |
| 5024 | "Content-Length: 15\r\n\r\n" |
| 5025 | "SOCKS5 Response"), |
| 5026 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5027 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5028 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5029 | |
| 5030 | MockWrite http_writes[] = { |
| 5031 | MockWrite(SYNCHRONOUS, |
| 5032 | "GET http://test/http HTTP/1.1\r\n" |
| 5033 | "Host: test\r\n" |
| 5034 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5035 | }; |
| 5036 | MockRead http_reads[] = { |
| 5037 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5038 | "Proxy-Connection: keep-alive\r\n" |
| 5039 | "Content-Length: 13\r\n\r\n" |
| 5040 | "HTTP Response"), |
| 5041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5042 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5043 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5044 | |
| 5045 | MockWrite https_writes[] = { |
| 5046 | MockWrite(SYNCHRONOUS, |
| 5047 | "GET http://test/https HTTP/1.1\r\n" |
| 5048 | "Host: test\r\n" |
| 5049 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5050 | }; |
| 5051 | MockRead https_reads[] = { |
| 5052 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5053 | "Proxy-Connection: keep-alive\r\n" |
| 5054 | "Content-Length: 14\r\n\r\n" |
| 5055 | "HTTPS Response"), |
| 5056 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5057 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5058 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5059 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5061 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5062 | MockWrite https_trusted_writes[] = { |
| 5063 | MockWrite(SYNCHRONOUS, |
| 5064 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5065 | "Host: test\r\n" |
| 5066 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5067 | }; |
| 5068 | MockRead https_trusted_reads[] = { |
| 5069 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5070 | "Proxy-Connection: keep-alive\r\n" |
| 5071 | "Content-Length: 22\r\n\r\n" |
| 5072 | "HTTPS Trusted Response"), |
| 5073 | }; |
| 5074 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5075 | https_trusted_writes); |
| 5076 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5077 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5079 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5080 | struct TestCase { |
| 5081 | GURL url; |
| 5082 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5083 | // 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] | 5084 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5085 | int expected_idle_socks4_sockets; |
| 5086 | int expected_idle_socks5_sockets; |
| 5087 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5088 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5089 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5090 | int expected_idle_https_sockets; |
| 5091 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5092 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5093 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5094 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5095 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5096 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5097 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5098 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5099 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5100 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5101 | }; |
| 5102 | |
| 5103 | for (const auto& test_case : kTestCases) { |
| 5104 | HttpRequestInfo request; |
| 5105 | request.method = "GET"; |
| 5106 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5107 | request.traffic_annotation = |
| 5108 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5109 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5110 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5111 | session.get()); |
| 5112 | TestCompletionCallback callback; |
| 5113 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5114 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5115 | |
| 5116 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5117 | ASSERT_TRUE(response); |
| 5118 | ASSERT_TRUE(response->headers); |
| 5119 | EXPECT_EQ(200, response->headers->response_code()); |
| 5120 | std::string response_data; |
| 5121 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5122 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5123 | |
| 5124 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5125 | // the next requests. |
| 5126 | trans.reset(); |
| 5127 | base::RunLoop().RunUntilIdle(); |
| 5128 | |
| 5129 | // Check the number of idle sockets in the pool, to make sure that used |
| 5130 | // sockets are indeed being returned to the socket pool. If each request |
| 5131 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5132 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5133 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5134 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5135 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5136 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5137 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5138 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5139 | ProxyHostPortPair())) |
| 5140 | ->IdleSocketCount()); |
| 5141 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5142 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5143 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5144 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5145 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5146 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5147 | ProxyHostPortPair())) |
| 5148 | ->IdleSocketCount()); |
| 5149 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5150 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5151 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5152 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5153 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5154 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5155 | ProxyHostPortPair())) |
| 5156 | ->IdleSocketCount()); |
| 5157 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5158 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5159 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5160 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5161 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5162 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5163 | ProxyHostPortPair())) |
| 5164 | ->IdleSocketCount()); |
| 5165 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5166 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5167 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5168 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5169 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5170 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5171 | ProxyHostPortPair(), |
| 5172 | true /* is_trusted_proxy */)) |
| 5173 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5174 | } |
| 5175 | } |
| 5176 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5177 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5178 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5179 | HttpRequestInfo request1; |
| 5180 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5181 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5182 | request1.traffic_annotation = |
| 5183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5184 | |
| 5185 | HttpRequestInfo request2; |
| 5186 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5187 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5188 | request2.traffic_annotation = |
| 5189 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5190 | |
| 5191 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5192 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5193 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5194 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5195 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5197 | |
| 5198 | // Since we have proxy, should try to establish tunnel. |
| 5199 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5200 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5201 | "Host: www.example.org:443\r\n" |
| 5202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5203 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5204 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5205 | "Host: www.example.org\r\n" |
| 5206 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5207 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5208 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5209 | "Host: www.example.org\r\n" |
| 5210 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5211 | }; |
| 5212 | |
| 5213 | // The proxy responds to the connect with a 407, using a persistent |
| 5214 | // connection. |
| 5215 | MockRead data_reads1[] = { |
| 5216 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5217 | |
| 5218 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5219 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5220 | MockRead(SYNCHRONOUS, "1"), |
| 5221 | |
| 5222 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5223 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5224 | MockRead(SYNCHRONOUS, "22"), |
| 5225 | }; |
| 5226 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5227 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5228 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5229 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5230 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5233 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5234 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5235 | |
| 5236 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5237 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5238 | |
| 5239 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5241 | |
| 5242 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5243 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5244 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5245 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5246 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5247 | |
| 5248 | LoadTimingInfo load_timing_info1; |
| 5249 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5250 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5251 | |
| 5252 | trans1.reset(); |
| 5253 | |
| 5254 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5255 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5256 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5257 | |
| 5258 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5260 | |
| 5261 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5263 | |
| 5264 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5265 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5266 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5267 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5268 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5269 | |
| 5270 | LoadTimingInfo load_timing_info2; |
| 5271 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5272 | TestLoadTimingReused(load_timing_info2); |
| 5273 | |
| 5274 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5275 | |
| 5276 | trans2.reset(); |
| 5277 | session->CloseAllConnections(); |
| 5278 | } |
| 5279 | |
| 5280 | // 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] | 5281 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5282 | HttpRequestInfo request1; |
| 5283 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5284 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5285 | request1.traffic_annotation = |
| 5286 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5287 | |
| 5288 | HttpRequestInfo request2; |
| 5289 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5290 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5291 | request2.traffic_annotation = |
| 5292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5293 | |
| 5294 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5295 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5296 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5297 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5298 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5299 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5301 | |
| 5302 | // Since we have proxy, should try to establish tunnel. |
| 5303 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5304 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5305 | "Host: www.example.org:443\r\n" |
| 5306 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5307 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5308 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5309 | "Host: www.example.org\r\n" |
| 5310 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5311 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5312 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5313 | "Host: www.example.org\r\n" |
| 5314 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5315 | }; |
| 5316 | |
| 5317 | // The proxy responds to the connect with a 407, using a persistent |
| 5318 | // connection. |
| 5319 | MockRead data_reads1[] = { |
| 5320 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5321 | |
| 5322 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5323 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5324 | MockRead(SYNCHRONOUS, "1"), |
| 5325 | |
| 5326 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5327 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5328 | MockRead(SYNCHRONOUS, "22"), |
| 5329 | }; |
| 5330 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5331 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5332 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5333 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5337 | auto trans1 = |
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 | int rv = trans1->Start(&request1, callback1.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 = callback1.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* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5347 | ASSERT_TRUE(response1); |
| 5348 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5349 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5350 | |
| 5351 | LoadTimingInfo load_timing_info1; |
| 5352 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5353 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5354 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5355 | |
| 5356 | trans1.reset(); |
| 5357 | |
| 5358 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5359 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5360 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5361 | |
| 5362 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5364 | |
| 5365 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5366 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5367 | |
| 5368 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5369 | ASSERT_TRUE(response2); |
| 5370 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5371 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5372 | |
| 5373 | LoadTimingInfo load_timing_info2; |
| 5374 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5375 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5376 | |
| 5377 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5378 | |
| 5379 | trans2.reset(); |
| 5380 | session->CloseAllConnections(); |
| 5381 | } |
| 5382 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5383 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5384 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5385 | HttpRequestInfo request; |
| 5386 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5387 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5388 | request.traffic_annotation = |
| 5389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5390 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5391 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5392 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5393 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5394 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5395 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5397 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5398 | // Since we have proxy, should use full url |
| 5399 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5400 | MockWrite( |
| 5401 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5402 | "Host: www.example.org\r\n" |
| 5403 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5404 | }; |
| 5405 | |
| 5406 | MockRead data_reads1[] = { |
| 5407 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5408 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5409 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5410 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 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] | 8ddf832 | 2012-02-23 18:08:06 | [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] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5418 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5420 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5422 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5424 | |
| 5425 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5427 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5428 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5429 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5430 | TestLoadTimingNotReused(load_timing_info, |
| 5431 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5433 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5434 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5435 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5436 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5437 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5438 | EXPECT_EQ(200, response->headers->response_code()); |
| 5439 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5440 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5441 | |
| 5442 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5443 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5444 | } |
| 5445 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5446 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5447 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5448 | HttpRequestInfo request; |
| 5449 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5450 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5451 | request.traffic_annotation = |
| 5452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5453 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5454 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5455 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5456 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5457 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5458 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5460 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5461 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5462 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5463 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5464 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5465 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5466 | spdy::SpdySerializedFrame resp( |
| 5467 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5468 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5469 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5470 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5471 | }; |
| 5472 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5473 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5474 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5475 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5476 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5477 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5480 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5484 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5486 | |
| 5487 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5489 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5490 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5491 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5492 | TestLoadTimingNotReused(load_timing_info, |
| 5493 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5495 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5496 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5497 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5498 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5499 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5500 | |
| 5501 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5502 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5503 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5504 | } |
| 5505 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5506 | // Verifies that a session which races and wins against the owning transaction |
| 5507 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5508 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5509 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5510 | HttpRequestInfo request; |
| 5511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5512 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5513 | request.traffic_annotation = |
| 5514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5515 | |
| 5516 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5517 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5518 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5519 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5520 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5522 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5523 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5524 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5525 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5526 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5527 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5528 | spdy::SpdySerializedFrame resp( |
| 5529 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5530 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5531 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5532 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5533 | }; |
| 5534 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5535 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5536 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5537 | |
| 5538 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5539 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5541 | |
| 5542 | TestCompletionCallback callback1; |
| 5543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5545 | |
| 5546 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5547 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5549 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5551 | |
| 5552 | // Race a session to the proxy, which completes first. |
| 5553 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5554 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5555 | PRIVACY_MODE_DISABLED, |
| 5556 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5557 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5558 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5559 | |
| 5560 | // Unstall the resolution begun by the transaction. |
| 5561 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5562 | session_deps_.host_resolver->ResolveAllPending(); |
| 5563 | |
| 5564 | EXPECT_FALSE(callback1.have_result()); |
| 5565 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5566 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5568 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5569 | ASSERT_TRUE(response); |
| 5570 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5571 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5572 | |
| 5573 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5574 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5575 | EXPECT_EQ(kUploadData, response_data); |
| 5576 | } |
| 5577 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5578 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5579 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5580 | HttpRequestInfo request; |
| 5581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5582 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5583 | request.traffic_annotation = |
| 5584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5585 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5586 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5587 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5588 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5589 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5590 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5592 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5593 | // The first request will be a bare GET, the second request will be a |
| 5594 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5595 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5596 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5597 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5598 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5599 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5600 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5601 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5602 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5603 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5604 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5605 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5606 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5607 | }; |
| 5608 | |
| 5609 | // The first response is a 407 proxy authentication challenge, and the second |
| 5610 | // response will be a 200 response since the second request includes a valid |
| 5611 | // Authorization header. |
| 5612 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5613 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5614 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5615 | spdy::SpdySerializedFrame resp_authentication( |
| 5616 | spdy_util_.ConstructSpdyReplyError( |
| 5617 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5618 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5619 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5620 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5621 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5622 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5623 | spdy::SpdySerializedFrame body_data( |
| 5624 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5625 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5626 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5627 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5628 | CreateMockRead(resp_data, 4), |
| 5629 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5630 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5631 | }; |
| 5632 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5633 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5636 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5637 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5638 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5640 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5644 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5646 | |
| 5647 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5648 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5650 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5651 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5652 | ASSERT_TRUE(response); |
| 5653 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5654 | EXPECT_EQ(407, response->headers->response_code()); |
| 5655 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5656 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5658 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5660 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5662 | |
| 5663 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5666 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5667 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5668 | ASSERT_TRUE(response_restart); |
| 5669 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5670 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5671 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5672 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5673 | } |
| 5674 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5675 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5677 | HttpRequestInfo request; |
| 5678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5679 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5680 | request.traffic_annotation = |
| 5681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5682 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5683 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5684 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5685 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5686 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5687 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5689 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5691 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5692 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5693 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5694 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5695 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5696 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5697 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5698 | const char get[] = |
| 5699 | "GET / HTTP/1.1\r\n" |
| 5700 | "Host: www.example.org\r\n" |
| 5701 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5702 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5703 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5704 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5705 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5706 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5707 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5708 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5709 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5710 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5711 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5712 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5713 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5714 | |
| 5715 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5716 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5717 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5718 | }; |
| 5719 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5720 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5721 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5722 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5723 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5724 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5725 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5726 | }; |
| 5727 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5728 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5729 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5730 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5731 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5732 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5734 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5737 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5739 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5741 | |
| 5742 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5743 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5744 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5745 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5746 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5747 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5749 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5750 | ASSERT_TRUE(response); |
| 5751 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5752 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5753 | |
| 5754 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5755 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5756 | EXPECT_EQ("1234567890", response_data); |
| 5757 | } |
| 5758 | |
| 5759 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5760 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5761 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5762 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5763 | HttpRequestInfo request; |
| 5764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5765 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5766 | request.traffic_annotation = |
| 5767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5768 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5769 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5770 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5771 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5772 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5773 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5777 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5778 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5779 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5780 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5781 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5782 | // fetch https://www.example.org/ via SPDY |
| 5783 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5784 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5785 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5786 | spdy::SpdySerializedFrame wrapped_get( |
| 5787 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5788 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5789 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5790 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5791 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5792 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5793 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5794 | spdy::SpdySerializedFrame body( |
| 5795 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5796 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5797 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5798 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5799 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5800 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5801 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5802 | |
| 5803 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5804 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5805 | CreateMockWrite(window_update_get_resp, 6), |
| 5806 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5807 | }; |
| 5808 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5810 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5811 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5812 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5813 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5814 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5815 | }; |
| 5816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5817 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5818 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5820 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5821 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5822 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5823 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5824 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5827 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5831 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5832 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5833 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5834 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5835 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5836 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5838 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5839 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5840 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5841 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5843 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5844 | ASSERT_TRUE(response); |
| 5845 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5846 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5847 | |
| 5848 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5849 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5850 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5854 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5855 | HttpRequestInfo request; |
| 5856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5857 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5858 | request.traffic_annotation = |
| 5859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5860 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5861 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5862 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5863 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5864 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5865 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5868 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5870 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5871 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5872 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5873 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5874 | spdy::SpdySerializedFrame get( |
| 5875 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | |
| 5877 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5878 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5879 | }; |
| 5880 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5881 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5882 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5883 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5884 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5885 | }; |
| 5886 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5887 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5888 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5889 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5890 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5891 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5892 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5893 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5894 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5897 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5899 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5901 | |
| 5902 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5903 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5904 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5905 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5906 | } |
| 5907 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5908 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5909 | // is observed, but does exist by the time auth credentials are provided. |
| 5910 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5911 | // what causes the existing H2 session to be noticed and reused. |
| 5912 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5913 | ProxyConfig proxy_config; |
| 5914 | proxy_config.set_auto_detect(true); |
| 5915 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5916 | |
| 5917 | CapturingProxyResolver capturing_proxy_resolver; |
| 5918 | capturing_proxy_resolver.set_proxy_server( |
| 5919 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5920 | session_deps_.proxy_resolution_service = |
| 5921 | std::make_unique<ProxyResolutionService>( |
| 5922 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5923 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5924 | std::make_unique<CapturingProxyResolverFactory>( |
| 5925 | &capturing_proxy_resolver), |
| 5926 | nullptr); |
| 5927 | |
| 5928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5929 | |
| 5930 | const char kMyUrl[] = "https://www.example.org/"; |
| 5931 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5932 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5933 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5934 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5935 | |
| 5936 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5937 | spdy::SpdySerializedFrame get2( |
| 5938 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5939 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5940 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5941 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5942 | |
| 5943 | MockWrite auth_challenge_writes[] = { |
| 5944 | MockWrite(ASYNC, 0, |
| 5945 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5946 | "Host: www.example.org:443\r\n" |
| 5947 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5948 | }; |
| 5949 | |
| 5950 | MockRead auth_challenge_reads[] = { |
| 5951 | MockRead(ASYNC, 1, |
| 5952 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5953 | "Content-Length: 0\r\n" |
| 5954 | "Proxy-Connection: close\r\n" |
| 5955 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5956 | }; |
| 5957 | |
| 5958 | MockWrite spdy_writes[] = { |
| 5959 | MockWrite(ASYNC, 0, |
| 5960 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5961 | "Host: www.example.org:443\r\n" |
| 5962 | "Proxy-Connection: keep-alive\r\n" |
| 5963 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5964 | CreateMockWrite(get, 2), |
| 5965 | CreateMockWrite(get2, 5), |
| 5966 | }; |
| 5967 | |
| 5968 | MockRead spdy_reads[] = { |
| 5969 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5970 | CreateMockRead(get_resp, 3, ASYNC), |
| 5971 | CreateMockRead(body, 4, ASYNC), |
| 5972 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5973 | CreateMockRead(body2, 7, ASYNC), |
| 5974 | |
| 5975 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5976 | }; |
| 5977 | |
| 5978 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5979 | auth_challenge_writes); |
| 5980 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5981 | |
| 5982 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5983 | auth_challenge_writes); |
| 5984 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5985 | |
| 5986 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5987 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5988 | |
| 5989 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5990 | ssl.next_proto = kProtoHTTP2; |
| 5991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5992 | |
| 5993 | TestCompletionCallback callback; |
| 5994 | std::string response_data; |
| 5995 | |
| 5996 | // Run first request until an auth challenge is observed. |
| 5997 | HttpRequestInfo request1; |
| 5998 | request1.method = "GET"; |
| 5999 | request1.url = GURL(kMyUrl); |
| 6000 | request1.traffic_annotation = |
| 6001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6002 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6003 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6004 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6005 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6006 | ASSERT_TRUE(response); |
| 6007 | ASSERT_TRUE(response->headers); |
| 6008 | EXPECT_EQ(407, response->headers->response_code()); |
| 6009 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6010 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6011 | |
| 6012 | // Run second request until an auth challenge is observed. |
| 6013 | HttpRequestInfo request2; |
| 6014 | request2.method = "GET"; |
| 6015 | request2.url = GURL(kMyUrl); |
| 6016 | request2.traffic_annotation = |
| 6017 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6018 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6019 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6020 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6021 | response = trans2.GetResponseInfo(); |
| 6022 | ASSERT_TRUE(response); |
| 6023 | ASSERT_TRUE(response->headers); |
| 6024 | EXPECT_EQ(407, response->headers->response_code()); |
| 6025 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6026 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6027 | |
| 6028 | // Now provide credentials for the first request, and wait for it to complete. |
| 6029 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6030 | rv = callback.GetResult(rv); |
| 6031 | EXPECT_THAT(rv, IsOk()); |
| 6032 | response = trans1.GetResponseInfo(); |
| 6033 | ASSERT_TRUE(response); |
| 6034 | ASSERT_TRUE(response->headers); |
| 6035 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6036 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6037 | EXPECT_EQ(kUploadData, response_data); |
| 6038 | |
| 6039 | // Now provide credentials for the second request. It should notice the |
| 6040 | // existing session, and reuse it. |
| 6041 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6042 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6043 | response = trans2.GetResponseInfo(); |
| 6044 | ASSERT_TRUE(response); |
| 6045 | ASSERT_TRUE(response->headers); |
| 6046 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6047 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6048 | EXPECT_EQ(kUploadData, response_data); |
| 6049 | } |
| 6050 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6051 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6052 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6054 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6055 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6056 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6057 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6058 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6059 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6060 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6061 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6062 | |
| 6063 | HttpRequestInfo request1; |
| 6064 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6065 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6066 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6067 | request1.traffic_annotation = |
| 6068 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6069 | |
| 6070 | HttpRequestInfo request2; |
| 6071 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6072 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6073 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6074 | request2.traffic_annotation = |
| 6075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6076 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6077 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6078 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6079 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6080 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6081 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6082 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6083 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6084 | // Fetch https://www.example.org/ via HTTP. |
| 6085 | const char get1[] = |
| 6086 | "GET / HTTP/1.1\r\n" |
| 6087 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6088 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6089 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6090 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6091 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6092 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6093 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6094 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6095 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6096 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6097 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6098 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6099 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6100 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6101 | spdy::SpdyHeaderBlock connect2_block; |
| 6102 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6103 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6104 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6105 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6106 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6107 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6108 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6109 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6110 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6111 | // Fetch https://mail.example.org/ via HTTP. |
| 6112 | const char get2[] = |
| 6113 | "GET / HTTP/1.1\r\n" |
| 6114 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6115 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6116 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6117 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6118 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6119 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6120 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6121 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6122 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6123 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | |
| 6125 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6126 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6127 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6128 | }; |
| 6129 | |
| 6130 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6131 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6132 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6133 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6134 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6135 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6136 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6137 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6138 | }; |
| 6139 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6140 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6141 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | |
| 6143 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6144 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6146 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6148 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6150 | |
| 6151 | TestCompletionCallback callback; |
| 6152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6154 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6155 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6156 | |
| 6157 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6158 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6159 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6162 | ASSERT_TRUE(response); |
| 6163 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6164 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6165 | |
| 6166 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6167 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6168 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6169 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6171 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6172 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6173 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6174 | |
| 6175 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6176 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6177 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6178 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6179 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6180 | |
| 6181 | // The requests should have different IDs, since they each are using their own |
| 6182 | // separate stream. |
| 6183 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6185 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6186 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6190 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6191 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6192 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6193 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6194 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6195 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6196 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6197 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6198 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6199 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6200 | |
| 6201 | HttpRequestInfo request1; |
| 6202 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6203 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6205 | request1.traffic_annotation = |
| 6206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6207 | |
| 6208 | HttpRequestInfo request2; |
| 6209 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6210 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6211 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6212 | request2.traffic_annotation = |
| 6213 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6214 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6215 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6216 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6217 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6218 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6219 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6220 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6221 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6222 | // Fetch https://www.example.org/ via HTTP. |
| 6223 | const char get1[] = |
| 6224 | "GET / HTTP/1.1\r\n" |
| 6225 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6226 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6227 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6228 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6229 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6230 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6231 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6232 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6233 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6235 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6236 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6237 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6238 | // Fetch https://www.example.org/2 via HTTP. |
| 6239 | const char get2[] = |
| 6240 | "GET /2 HTTP/1.1\r\n" |
| 6241 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6242 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6243 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6244 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6245 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6246 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6247 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6248 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6249 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6250 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6251 | |
| 6252 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6253 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6254 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6255 | }; |
| 6256 | |
| 6257 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6258 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6259 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6260 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6261 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6262 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6263 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6264 | }; |
| 6265 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6266 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6267 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | |
| 6269 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6270 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6272 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6274 | |
| 6275 | TestCompletionCallback callback; |
| 6276 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6277 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6279 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6281 | |
| 6282 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6284 | |
| 6285 | LoadTimingInfo load_timing_info; |
| 6286 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6287 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6288 | |
| 6289 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6290 | ASSERT_TRUE(response); |
| 6291 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6292 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6293 | |
| 6294 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6295 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6296 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6297 | trans.reset(); |
| 6298 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6299 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6300 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6301 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6302 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6303 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6304 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6305 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6306 | |
| 6307 | LoadTimingInfo load_timing_info2; |
| 6308 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6309 | TestLoadTimingReused(load_timing_info2); |
| 6310 | |
| 6311 | // The requests should have the same ID. |
| 6312 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6313 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6314 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6315 | } |
| 6316 | |
| 6317 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6318 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6319 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6320 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6321 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6322 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6323 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6324 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6325 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6326 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6327 | |
| 6328 | HttpRequestInfo request1; |
| 6329 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6330 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6331 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6332 | request1.traffic_annotation = |
| 6333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6334 | |
| 6335 | HttpRequestInfo request2; |
| 6336 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6338 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6339 | request2.traffic_annotation = |
| 6340 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6341 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6342 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6343 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6344 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6345 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6346 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6347 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6348 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6349 | spdy::SpdySerializedFrame body1( |
| 6350 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6351 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6352 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6353 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6354 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6355 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6356 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6357 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6358 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6359 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6360 | spdy::SpdySerializedFrame body2( |
| 6361 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6362 | |
| 6363 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6364 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | }; |
| 6366 | |
| 6367 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6368 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6369 | CreateMockRead(body1, 2, ASYNC), |
| 6370 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6371 | CreateMockRead(body2, 5, ASYNC), |
| 6372 | MockRead(ASYNC, 0, 6), |
[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 | |
| 6382 | TestCompletionCallback callback; |
| 6383 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6384 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6385 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6386 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6387 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6388 | |
| 6389 | LoadTimingInfo load_timing_info; |
| 6390 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6391 | TestLoadTimingNotReused(load_timing_info, |
| 6392 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6393 | |
| 6394 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6395 | ASSERT_TRUE(response); |
| 6396 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6397 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6398 | |
| 6399 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6400 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6401 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6402 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6403 | // Delete the first request, so the second one can reuse the socket. |
| 6404 | trans.reset(); |
| 6405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6406 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6407 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6408 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6409 | |
| 6410 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6411 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6412 | TestLoadTimingReused(load_timing_info2); |
| 6413 | |
| 6414 | // The requests should have the same ID. |
| 6415 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6417 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6418 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6419 | } |
| 6420 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6421 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6422 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6423 | // would break socket pool isolation. |
| 6424 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6425 | ProxyConfig proxy_config; |
| 6426 | proxy_config.set_auto_detect(true); |
| 6427 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6428 | |
| 6429 | CapturingProxyResolver capturing_proxy_resolver; |
| 6430 | session_deps_.proxy_resolution_service = |
| 6431 | std::make_unique<ProxyResolutionService>( |
| 6432 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6433 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6434 | std::make_unique<CapturingProxyResolverFactory>( |
| 6435 | &capturing_proxy_resolver), |
| 6436 | nullptr); |
| 6437 | |
| 6438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6439 | |
| 6440 | SpdyTestUtil spdy_util1; |
| 6441 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6442 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6443 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6444 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6445 | // fetch https://www.example.org/ via HTTP/2. |
| 6446 | const char kMyUrl[] = "https://www.example.org/"; |
| 6447 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6448 | spdy::SpdySerializedFrame wrapped_get( |
| 6449 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6450 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6451 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6452 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6453 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6454 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6455 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6456 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6457 | spdy::SpdySerializedFrame wrapped_body( |
| 6458 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6459 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6460 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6461 | spdy::SpdySerializedFrame window_update_body( |
| 6462 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6463 | |
| 6464 | MockWrite spdy_writes1[] = { |
| 6465 | CreateMockWrite(connect, 0), |
| 6466 | CreateMockWrite(wrapped_get, 2), |
| 6467 | CreateMockWrite(window_update_get_resp, 6), |
| 6468 | CreateMockWrite(window_update_body, 7), |
| 6469 | }; |
| 6470 | |
| 6471 | MockRead spdy_reads1[] = { |
| 6472 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6473 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6474 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6475 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6476 | MockRead(ASYNC, 0, 8), |
| 6477 | }; |
| 6478 | |
| 6479 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6480 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6481 | |
| 6482 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6483 | // a new pipe. |
| 6484 | SpdyTestUtil spdy_util2; |
| 6485 | spdy::SpdySerializedFrame req( |
| 6486 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6487 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6488 | |
| 6489 | spdy::SpdySerializedFrame resp( |
| 6490 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6491 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6492 | MockRead spdy_reads2[] = { |
| 6493 | CreateMockRead(resp, 1), |
| 6494 | CreateMockRead(data, 2), |
| 6495 | MockRead(ASYNC, 0, 3), |
| 6496 | }; |
| 6497 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6498 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6499 | |
| 6500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6501 | ssl.next_proto = kProtoHTTP2; |
| 6502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6503 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6504 | ssl2.next_proto = kProtoHTTP2; |
| 6505 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6506 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6507 | ssl3.next_proto = kProtoHTTP2; |
| 6508 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6509 | |
| 6510 | TestCompletionCallback callback; |
| 6511 | std::string response_data; |
| 6512 | |
| 6513 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6514 | capturing_proxy_resolver.set_proxy_server( |
| 6515 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6516 | HttpRequestInfo request1; |
| 6517 | request1.method = "GET"; |
| 6518 | request1.url = GURL("https://www.example.org/"); |
| 6519 | request1.traffic_annotation = |
| 6520 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6521 | |
| 6522 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6523 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6524 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6525 | |
| 6526 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6527 | base::RunLoop().RunUntilIdle(); |
| 6528 | // Now allow the read of the response to complete. |
| 6529 | spdy_data1.Resume(); |
| 6530 | rv = callback.WaitForResult(); |
| 6531 | EXPECT_THAT(rv, IsOk()); |
| 6532 | |
| 6533 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6534 | ASSERT_TRUE(response); |
| 6535 | ASSERT_TRUE(response->headers); |
| 6536 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6537 | |
| 6538 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6539 | EXPECT_EQ(kUploadData, response_data); |
| 6540 | RunUntilIdle(); |
| 6541 | |
| 6542 | // Make a direct HTTP/2 request to proxy:70. |
| 6543 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6544 | HttpRequestInfo request2; |
| 6545 | request2.method = "GET"; |
| 6546 | request2.url = GURL("https://proxy:70/"); |
| 6547 | request2.traffic_annotation = |
| 6548 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6549 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6550 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6551 | NetLogWithSource())), |
| 6552 | IsOk()); |
| 6553 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6554 | } |
| 6555 | |
| 6556 | // Same as above, but reverse request order, since the code to check for an |
| 6557 | // existing session is different for tunnels and direct connections. |
| 6558 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6559 | // Configure against https proxy server "myproxy:80". |
| 6560 | ProxyConfig proxy_config; |
| 6561 | proxy_config.set_auto_detect(true); |
| 6562 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6563 | |
| 6564 | CapturingProxyResolver capturing_proxy_resolver; |
| 6565 | session_deps_.proxy_resolution_service = |
| 6566 | std::make_unique<ProxyResolutionService>( |
| 6567 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6568 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6569 | std::make_unique<CapturingProxyResolverFactory>( |
| 6570 | &capturing_proxy_resolver), |
| 6571 | nullptr); |
| 6572 | |
| 6573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6574 | // Fetch https://proxy:70/ via HTTP/2. |
| 6575 | SpdyTestUtil spdy_util1; |
| 6576 | spdy::SpdySerializedFrame req( |
| 6577 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6578 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6579 | |
| 6580 | spdy::SpdySerializedFrame resp( |
| 6581 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6582 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6583 | MockRead spdy_reads1[] = { |
| 6584 | CreateMockRead(resp, 1), |
| 6585 | CreateMockRead(data, 2), |
| 6586 | MockRead(ASYNC, 0, 3), |
| 6587 | }; |
| 6588 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6589 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6590 | |
| 6591 | SpdyTestUtil spdy_util2; |
| 6592 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6593 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6594 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6595 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6596 | // fetch https://www.example.org/ via HTTP/2. |
| 6597 | const char kMyUrl[] = "https://www.example.org/"; |
| 6598 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6599 | spdy::SpdySerializedFrame wrapped_get( |
| 6600 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6601 | spdy::SpdySerializedFrame conn_resp( |
| 6602 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6603 | spdy::SpdySerializedFrame get_resp( |
| 6604 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6605 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6606 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6607 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6608 | spdy::SpdySerializedFrame wrapped_body( |
| 6609 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6610 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6611 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6612 | spdy::SpdySerializedFrame window_update_body( |
| 6613 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6614 | |
| 6615 | MockWrite spdy_writes2[] = { |
| 6616 | CreateMockWrite(connect, 0), |
| 6617 | CreateMockWrite(wrapped_get, 2), |
| 6618 | CreateMockWrite(window_update_get_resp, 6), |
| 6619 | CreateMockWrite(window_update_body, 7), |
| 6620 | }; |
| 6621 | |
| 6622 | MockRead spdy_reads2[] = { |
| 6623 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6624 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6625 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6626 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6627 | MockRead(ASYNC, 0, 8), |
| 6628 | }; |
| 6629 | |
| 6630 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6631 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6632 | |
| 6633 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6634 | ssl.next_proto = kProtoHTTP2; |
| 6635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6636 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6637 | ssl2.next_proto = kProtoHTTP2; |
| 6638 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6639 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6640 | ssl3.next_proto = kProtoHTTP2; |
| 6641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6642 | |
| 6643 | TestCompletionCallback callback; |
| 6644 | std::string response_data; |
| 6645 | |
| 6646 | // Make a direct HTTP/2 request to proxy:70. |
| 6647 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6648 | HttpRequestInfo request1; |
| 6649 | request1.method = "GET"; |
| 6650 | request1.url = GURL("https://proxy:70/"); |
| 6651 | request1.traffic_annotation = |
| 6652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6653 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6654 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6655 | NetLogWithSource())), |
| 6656 | IsOk()); |
| 6657 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6658 | RunUntilIdle(); |
| 6659 | |
| 6660 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6661 | capturing_proxy_resolver.set_proxy_server( |
| 6662 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6663 | HttpRequestInfo request2; |
| 6664 | request2.method = "GET"; |
| 6665 | request2.url = GURL("https://www.example.org/"); |
| 6666 | request2.traffic_annotation = |
| 6667 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6668 | |
| 6669 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6670 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6672 | |
| 6673 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6674 | base::RunLoop().RunUntilIdle(); |
| 6675 | // Now allow the read of the response to complete. |
| 6676 | spdy_data2.Resume(); |
| 6677 | rv = callback.WaitForResult(); |
| 6678 | EXPECT_THAT(rv, IsOk()); |
| 6679 | |
| 6680 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6681 | ASSERT_TRUE(response2); |
| 6682 | ASSERT_TRUE(response2->headers); |
| 6683 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6684 | |
| 6685 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6686 | EXPECT_EQ(kUploadData, response_data); |
| 6687 | } |
| 6688 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6689 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6690 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6691 | HttpRequestInfo request; |
| 6692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6694 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6695 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6696 | request.traffic_annotation = |
| 6697 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6698 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6699 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6700 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6701 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6702 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6703 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6705 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6706 | // Since we have proxy, should use full url |
| 6707 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6708 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6709 | "Host: www.example.org\r\n" |
| 6710 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6712 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6713 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6714 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6715 | "Host: www.example.org\r\n" |
| 6716 | "Proxy-Connection: keep-alive\r\n" |
| 6717 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6718 | }; |
| 6719 | |
| 6720 | // The proxy responds to the GET with a 407, using a persistent |
| 6721 | // connection. |
| 6722 | MockRead data_reads1[] = { |
| 6723 | // No credentials. |
| 6724 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6725 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6726 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6727 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6728 | |
| 6729 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6730 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6731 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6733 | }; |
| 6734 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6735 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6737 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6738 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6740 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6742 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6744 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6746 | |
| 6747 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6748 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6749 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6750 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6751 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6752 | TestLoadTimingNotReused(load_timing_info, |
| 6753 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6755 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6756 | ASSERT_TRUE(response); |
| 6757 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6758 | EXPECT_EQ(407, response->headers->response_code()); |
| 6759 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6760 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6761 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6762 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6763 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6765 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6767 | |
| 6768 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6769 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6770 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6771 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6772 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6773 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6774 | TestLoadTimingReused(load_timing_info); |
| 6775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6776 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6777 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6778 | |
| 6779 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6780 | EXPECT_EQ(200, response->headers->response_code()); |
| 6781 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6782 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6783 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6784 | |
| 6785 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6786 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6787 | } |
| 6788 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6789 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6790 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6791 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6793 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6794 | request.traffic_annotation = |
| 6795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6796 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6797 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6798 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6799 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6800 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6801 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6802 | // Since we have proxy, should try to establish tunnel. |
| 6803 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6804 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6805 | "Host: www.example.org:443\r\n" |
| 6806 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6807 | }; |
| 6808 | |
| 6809 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6810 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6811 | // No response body because the test stops reading here. |
| 6812 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6813 | }; |
| 6814 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6815 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6816 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6818 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6820 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6821 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6822 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | |
| 6825 | rv = callback.WaitForResult(); |
| 6826 | EXPECT_EQ(expected_status, rv); |
| 6827 | } |
| 6828 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6829 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6830 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6831 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6832 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6833 | } |
| 6834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6835 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6836 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6837 | } |
| 6838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6839 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6840 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6841 | } |
| 6842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6843 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6844 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6845 | } |
| 6846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6847 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6848 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6849 | } |
| 6850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6851 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6852 | ConnectStatusHelper( |
| 6853 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6894 | } |
| 6895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6897 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6910 | } |
| 6911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6913 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6914 | } |
| 6915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6916 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6917 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6918 | } |
| 6919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6920 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6921 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6922 | } |
| 6923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6924 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6925 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6926 | } |
| 6927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6928 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6929 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6930 | } |
| 6931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6932 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6933 | ConnectStatusHelperWithExpectedStatus( |
| 6934 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6935 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6948 | } |
| 6949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6951 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6952 | } |
| 6953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6955 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6956 | } |
| 6957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6959 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6960 | } |
| 6961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6963 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6964 | } |
| 6965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6967 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6968 | } |
| 6969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6971 | ConnectStatusHelper( |
| 6972 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6973 | } |
| 6974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6976 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6977 | } |
| 6978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6980 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6981 | } |
| 6982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6983 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6984 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6985 | } |
| 6986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6987 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6988 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6989 | } |
| 6990 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6991 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6992 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6993 | } |
| 6994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6995 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6996 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6997 | } |
| 6998 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6999 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 7000 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 7001 | } |
| 7002 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7003 | // Test the flow when both the proxy server AND origin server require |
| 7004 | // authentication. Again, this uses basic auth for both since that is |
| 7005 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7006 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7007 | HttpRequestInfo request; |
| 7008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7009 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7010 | request.traffic_annotation = |
| 7011 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7012 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7013 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7014 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7015 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7019 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7020 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7021 | MockWrite( |
| 7022 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7023 | "Host: www.example.org\r\n" |
| 7024 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7025 | }; |
| 7026 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7027 | MockRead data_reads1[] = { |
| 7028 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7029 | // Give a couple authenticate options (only the middle one is actually |
| 7030 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7031 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7032 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7033 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7034 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7035 | // Large content-length -- won't matter, as connection will be reset. |
| 7036 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7037 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7038 | }; |
| 7039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7040 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7041 | // request we should be issuing -- the final header line contains the |
| 7042 | // proxy's credentials. |
| 7043 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7044 | MockWrite( |
| 7045 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7046 | "Host: www.example.org\r\n" |
| 7047 | "Proxy-Connection: keep-alive\r\n" |
| 7048 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7049 | }; |
| 7050 | |
| 7051 | // Now the proxy server lets the request pass through to origin server. |
| 7052 | // The origin server responds with a 401. |
| 7053 | MockRead data_reads2[] = { |
| 7054 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7055 | // Note: We are using the same realm-name as the proxy server. This is |
| 7056 | // completely valid, as realms are unique across hosts. |
| 7057 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7058 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7059 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7060 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7061 | }; |
| 7062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7063 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7064 | // the credentials for both the proxy and origin server. |
| 7065 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7066 | MockWrite( |
| 7067 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7068 | "Host: www.example.org\r\n" |
| 7069 | "Proxy-Connection: keep-alive\r\n" |
| 7070 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7071 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7072 | }; |
| 7073 | |
| 7074 | // Lastly we get the desired content. |
| 7075 | MockRead data_reads3[] = { |
| 7076 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7077 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7078 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7079 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | }; |
| 7081 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7082 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7083 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7084 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7085 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7086 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7087 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7089 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7090 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7091 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7093 | |
| 7094 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7097 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7098 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7099 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7101 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7103 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7105 | |
| 7106 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7107 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7108 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7109 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7110 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7111 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7113 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7115 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7116 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7118 | |
| 7119 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7122 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7123 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7124 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7125 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7126 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7127 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7128 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7129 | // authorization headers. |
| 7130 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7131 | // The NTLM authentication unit tests are based on known test data from the |
| 7132 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7133 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7134 | // for the implementation and testing of the protocol. |
| 7135 | // |
| 7136 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7137 | |
| 7138 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7139 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7140 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7141 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7142 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7143 | request.traffic_annotation = |
| 7144 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7145 | |
| 7146 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7147 | // to other auth schemes. |
| 7148 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7149 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7150 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7151 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7152 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7153 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7154 | // Generate the NTLM messages based on known test data. |
| 7155 | std::string negotiate_msg; |
| 7156 | std::string challenge_msg; |
| 7157 | std::string authenticate_msg; |
| 7158 | base::Base64Encode( |
| 7159 | base::StringPiece( |
| 7160 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7161 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7162 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7163 | base::Base64Encode( |
| 7164 | base::StringPiece( |
| 7165 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7166 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7167 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7168 | base::Base64Encode( |
| 7169 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7170 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7171 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7172 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7173 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7174 | &authenticate_msg); |
| 7175 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7176 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7177 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7178 | "Host: server\r\n" |
| 7179 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7180 | }; |
| 7181 | |
| 7182 | MockRead data_reads1[] = { |
| 7183 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7184 | // Negotiate and NTLM are often requested together. However, we only want |
| 7185 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7186 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7187 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7188 | MockRead("Connection: close\r\n"), |
| 7189 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7190 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7191 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7192 | }; |
| 7193 | |
| 7194 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7195 | // After restarting with a null identity, this is the |
| 7196 | // request we should be issuing -- the final header line contains a Type |
| 7197 | // 1 message. |
| 7198 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7199 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7200 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7201 | "Authorization: NTLM "), |
| 7202 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7204 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7205 | // (using correct credentials). The second request continues on the |
| 7206 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7207 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7208 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7209 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7210 | "Authorization: NTLM "), |
| 7211 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7212 | }; |
| 7213 | |
| 7214 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7215 | // The origin server responds with a Type 2 message. |
| 7216 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7217 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7218 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7219 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7220 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7221 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7222 | // Lastly we get the desired content. |
| 7223 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7224 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7225 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7226 | }; |
| 7227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7228 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7229 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7230 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7231 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7232 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7233 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7235 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7238 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7241 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7242 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7244 | |
| 7245 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7248 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7250 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7251 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7252 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7253 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7254 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7255 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7256 | rv = trans.RestartWithAuth( |
| 7257 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7258 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7260 | |
| 7261 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7264 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7265 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7266 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7267 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7268 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7270 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7272 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7274 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7275 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7278 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7279 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7280 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7281 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7282 | |
| 7283 | std::string response_data; |
| 7284 | rv = ReadTransaction(&trans, &response_data); |
| 7285 | EXPECT_THAT(rv, IsOk()); |
| 7286 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7287 | |
| 7288 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7289 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7290 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7291 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7292 | } |
| 7293 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7294 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7295 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7296 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7297 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7298 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7299 | request.traffic_annotation = |
| 7300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7301 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7302 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7303 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7305 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7306 | // Generate the NTLM messages based on known test data. |
| 7307 | std::string negotiate_msg; |
| 7308 | std::string challenge_msg; |
| 7309 | std::string authenticate_msg; |
| 7310 | base::Base64Encode( |
| 7311 | base::StringPiece( |
| 7312 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7313 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7314 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7315 | base::Base64Encode( |
| 7316 | base::StringPiece( |
| 7317 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7318 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7319 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7320 | base::Base64Encode( |
| 7321 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7322 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7323 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7324 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7325 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7326 | &authenticate_msg); |
| 7327 | |
| 7328 | // The authenticate message when |kWrongPassword| is sent. |
| 7329 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7330 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7331 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7332 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7333 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7334 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7335 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7336 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7337 | // Sanity check that it's the same length as the correct authenticate message |
| 7338 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7339 | ASSERT_EQ(authenticate_msg.length(), |
| 7340 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7341 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7342 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7343 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7344 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7345 | "Host: server\r\n" |
| 7346 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7347 | }; |
| 7348 | |
| 7349 | MockRead data_reads1[] = { |
| 7350 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7351 | // Negotiate and NTLM are often requested together. However, we only want |
| 7352 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7353 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7354 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7355 | MockRead("Connection: close\r\n"), |
| 7356 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7357 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7358 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7359 | }; |
| 7360 | |
| 7361 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7362 | // After restarting with a null identity, this is the |
| 7363 | // request we should be issuing -- the final header line contains a Type |
| 7364 | // 1 message. |
| 7365 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7366 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7367 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7368 | "Authorization: NTLM "), |
| 7369 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7371 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7372 | // (using incorrect credentials). The second request continues on the |
| 7373 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7374 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7375 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7376 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7377 | "Authorization: NTLM "), |
| 7378 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7379 | }; |
| 7380 | |
| 7381 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7382 | // The origin server responds with a Type 2 message. |
| 7383 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7384 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7385 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7386 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7387 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7388 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7389 | // Wrong password. |
| 7390 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7391 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7392 | MockRead("Content-Length: 42\r\n"), |
| 7393 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7394 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7395 | }; |
| 7396 | |
| 7397 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | // After restarting with a null identity, this is the |
| 7399 | // request we should be issuing -- the final header line contains a Type |
| 7400 | // 1 message. |
| 7401 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7402 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7403 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7404 | "Authorization: NTLM "), |
| 7405 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7408 | // (the credentials for the origin server). The second request continues |
| 7409 | // on the same connection. |
| 7410 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7411 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7412 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7413 | "Authorization: NTLM "), |
| 7414 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7415 | }; |
| 7416 | |
| 7417 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7418 | // The origin server responds with a Type 2 message. |
| 7419 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7420 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7421 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7422 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7423 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7424 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7425 | // Lastly we get the desired content. |
| 7426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7427 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7428 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7429 | }; |
| 7430 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7431 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7432 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7433 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7434 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7435 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7436 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7437 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7438 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7440 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7441 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7442 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7443 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7445 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7448 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7449 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7451 | |
| 7452 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7455 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7457 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7458 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7459 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7461 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7462 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7463 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7464 | rv = trans.RestartWithAuth( |
| 7465 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7466 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7468 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7469 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7472 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7473 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7474 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7476 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7481 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7482 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7483 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7484 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7485 | |
| 7486 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7487 | rv = trans.RestartWithAuth( |
| 7488 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7489 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7491 | |
| 7492 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7493 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7495 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7497 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7498 | |
| 7499 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7500 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7501 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7502 | |
| 7503 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7504 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7506 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7507 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7508 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7509 | |
| 7510 | std::string response_data; |
| 7511 | rv = ReadTransaction(&trans, &response_data); |
| 7512 | EXPECT_THAT(rv, IsOk()); |
| 7513 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7514 | |
| 7515 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7516 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7517 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7518 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7519 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7520 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7521 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7522 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7523 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7524 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7525 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7526 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7527 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7528 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7529 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7530 | |
| 7531 | HttpRequestInfo request; |
| 7532 | request.method = "GET"; |
| 7533 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7534 | request.traffic_annotation = |
| 7535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7536 | |
| 7537 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7538 | spdy::SpdyHeaderBlock request_headers0( |
| 7539 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7540 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7541 | 1, std::move(request_headers0), LOWEST, true)); |
| 7542 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7543 | spdy::SpdyHeaderBlock response_headers0; |
| 7544 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7545 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7546 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7547 | 1, std::move(response_headers0), true)); |
| 7548 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7549 | // Stream 1 is closed. |
| 7550 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7551 | |
| 7552 | // Generate the NTLM messages based on known test data. |
| 7553 | std::string negotiate_msg; |
| 7554 | std::string challenge_msg; |
| 7555 | std::string authenticate_msg; |
| 7556 | base::Base64Encode( |
| 7557 | base::StringPiece( |
| 7558 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7559 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7560 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7561 | base::Base64Encode( |
| 7562 | base::StringPiece( |
| 7563 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7564 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7565 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7566 | base::Base64Encode( |
| 7567 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7568 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7569 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7570 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7571 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7572 | &authenticate_msg); |
| 7573 | |
| 7574 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7575 | spdy::SpdyHeaderBlock request_headers1( |
| 7576 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7577 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7578 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7579 | 3, std::move(request_headers1), LOWEST, true)); |
| 7580 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7581 | spdy::SpdySerializedFrame rst( |
| 7582 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7583 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7584 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7585 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | |
| 7587 | // Retry yet again using HTTP/1.1. |
| 7588 | MockWrite writes1[] = { |
| 7589 | // After restarting with a null identity, this is the |
| 7590 | // request we should be issuing -- the final header line contains a Type |
| 7591 | // 1 message. |
| 7592 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7593 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7594 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7595 | "Authorization: NTLM "), |
| 7596 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7597 | |
| 7598 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7599 | // (the credentials for the origin server). The second request continues |
| 7600 | // on the same connection. |
| 7601 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7602 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7603 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7604 | "Authorization: NTLM "), |
| 7605 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7606 | }; |
| 7607 | |
| 7608 | MockRead reads1[] = { |
| 7609 | // The origin server responds with a Type 2 message. |
| 7610 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7611 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7612 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7613 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7614 | MockRead("You are not authorized to view this page\r\n"), |
| 7615 | |
| 7616 | // Lastly we get the desired content. |
| 7617 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7618 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7619 | 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] | 7620 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7621 | SequencedSocketData data0(reads0, writes0); |
| 7622 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7623 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7624 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7625 | |
| 7626 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7627 | ssl0.next_proto = kProtoHTTP2; |
| 7628 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7631 | |
| 7632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7634 | |
| 7635 | TestCompletionCallback callback1; |
| 7636 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7638 | |
| 7639 | rv = callback1.WaitForResult(); |
| 7640 | EXPECT_THAT(rv, IsOk()); |
| 7641 | |
| 7642 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7643 | |
| 7644 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7645 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7646 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7647 | |
| 7648 | TestCompletionCallback callback2; |
| 7649 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7650 | rv = trans.RestartWithAuth( |
| 7651 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7652 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7654 | |
| 7655 | rv = callback2.WaitForResult(); |
| 7656 | EXPECT_THAT(rv, IsOk()); |
| 7657 | |
| 7658 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7659 | |
| 7660 | response = trans.GetResponseInfo(); |
| 7661 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7662 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7663 | |
| 7664 | TestCompletionCallback callback3; |
| 7665 | |
| 7666 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7668 | |
| 7669 | rv = callback3.WaitForResult(); |
| 7670 | EXPECT_THAT(rv, IsOk()); |
| 7671 | |
| 7672 | response = trans.GetResponseInfo(); |
| 7673 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7674 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7675 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7676 | |
| 7677 | std::string response_data; |
| 7678 | rv = ReadTransaction(&trans, &response_data); |
| 7679 | EXPECT_THAT(rv, IsOk()); |
| 7680 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7681 | |
| 7682 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7683 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7684 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7685 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7686 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7687 | |
| 7688 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7689 | // do no retry forever checking for TLS version interference. This is a |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7690 | // regression test for https://crbug.com/823387. The version interference probe |
| 7691 | // has since been removed, but retain the regression test so we can update it if |
| 7692 | // we add future TLS retries. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7693 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7694 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7695 | // https://origin/. |
| 7696 | session_deps_.proxy_resolution_service = |
| 7697 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7698 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7699 | |
| 7700 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7701 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7702 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7703 | |
| 7704 | HttpRequestInfo request; |
| 7705 | request.method = "GET"; |
| 7706 | request.url = GURL("https://origin/"); |
| 7707 | request.traffic_annotation = |
| 7708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7709 | |
| 7710 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7711 | // to other auth schemes. |
| 7712 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7713 | |
| 7714 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7715 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7717 | |
| 7718 | // Generate the NTLM messages based on known test data. |
| 7719 | std::string negotiate_msg; |
| 7720 | std::string challenge_msg; |
| 7721 | std::string authenticate_msg; |
| 7722 | base::Base64Encode( |
| 7723 | base::StringPiece( |
| 7724 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7725 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7726 | &negotiate_msg); |
| 7727 | base::Base64Encode( |
| 7728 | base::StringPiece( |
| 7729 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7730 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7731 | &challenge_msg); |
| 7732 | base::Base64Encode( |
| 7733 | base::StringPiece( |
| 7734 | reinterpret_cast<const char*>( |
| 7735 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7736 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7737 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7738 | &authenticate_msg); |
| 7739 | |
| 7740 | MockWrite data_writes[] = { |
| 7741 | // The initial CONNECT request. |
| 7742 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7743 | "Host: origin:443\r\n" |
| 7744 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7745 | |
| 7746 | // After restarting with an identity. |
| 7747 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7748 | "Host: origin:443\r\n" |
| 7749 | "Proxy-Connection: keep-alive\r\n" |
| 7750 | "Proxy-Authorization: NTLM "), |
| 7751 | MockWrite(negotiate_msg.c_str()), |
| 7752 | // End headers. |
| 7753 | MockWrite("\r\n\r\n"), |
| 7754 | |
| 7755 | // The second restart. |
| 7756 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7757 | "Host: origin:443\r\n" |
| 7758 | "Proxy-Connection: keep-alive\r\n" |
| 7759 | "Proxy-Authorization: NTLM "), |
| 7760 | MockWrite(authenticate_msg.c_str()), |
| 7761 | // End headers. |
| 7762 | MockWrite("\r\n\r\n"), |
| 7763 | }; |
| 7764 | |
| 7765 | MockRead data_reads[] = { |
| 7766 | // The initial NTLM response. |
| 7767 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7768 | "Content-Length: 0\r\n" |
| 7769 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7770 | |
| 7771 | // The NTLM challenge message. |
| 7772 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7773 | "Content-Length: 0\r\n" |
| 7774 | "Proxy-Authenticate: NTLM "), |
| 7775 | MockRead(challenge_msg.c_str()), |
| 7776 | // End headers. |
| 7777 | MockRead("\r\n\r\n"), |
| 7778 | |
| 7779 | // Finally the tunnel is established. |
| 7780 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7781 | }; |
| 7782 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7783 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7784 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7787 | |
| 7788 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7789 | // request. |
| 7790 | TestCompletionCallback callback; |
| 7791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7792 | int rv = callback.GetResult( |
| 7793 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7794 | |
| 7795 | EXPECT_THAT(rv, IsOk()); |
| 7796 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7797 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7798 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7799 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7800 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7801 | // Configure credentials and restart. The proxy responds with the challenge |
| 7802 | // message. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7803 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7804 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7805 | callback.callback())); |
| 7806 | EXPECT_THAT(rv, IsOk()); |
| 7807 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7808 | response = trans.GetResponseInfo(); |
| 7809 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7810 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7811 | |
David Benjamin | d61bd53 | 2019-04-23 21:11:37 | [diff] [blame] | 7812 | // Restart once more. The tunnel will be established and then the SSL |
| 7813 | // handshake will reset. |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7814 | rv = callback.GetResult( |
| 7815 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7816 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7817 | } |
| 7818 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7819 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7820 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7821 | // Test reading a server response which has only headers, and no body. |
| 7822 | // After some maximum number of bytes is consumed, the transaction should |
| 7823 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7824 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7825 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7826 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7827 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7828 | request.traffic_annotation = |
| 7829 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7830 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7833 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7834 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7835 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7836 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | |
| 7838 | MockRead data_reads[] = { |
| 7839 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7840 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7841 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7842 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7843 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7844 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7846 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7847 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7849 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7851 | |
| 7852 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7853 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7854 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7855 | |
| 7856 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7857 | // establish tunnel. |
| 7858 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7859 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7860 | HttpRequestInfo request; |
| 7861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7862 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7863 | request.traffic_annotation = |
| 7864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7865 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7866 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7867 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7868 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7871 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7872 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7873 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7874 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7875 | // Since we have proxy, should try to establish tunnel. |
| 7876 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7878 | "Host: www.example.org:443\r\n" |
| 7879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7880 | }; |
| 7881 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7882 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7883 | // connection. Usually a proxy would return 501 (not implemented), |
| 7884 | // or 200 (tunnel established). |
| 7885 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7886 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7887 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7888 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7889 | }; |
| 7890 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7891 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7892 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7894 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7896 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7898 | |
| 7899 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7900 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7901 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7902 | // Empty the current queue. This is necessary because idle sockets are |
| 7903 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7904 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7905 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7906 | // We now check to make sure the TCPClientSocket was not added back to |
| 7907 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7908 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7909 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7910 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7911 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7912 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7913 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7914 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7915 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7916 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7917 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7919 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7920 | request.traffic_annotation = |
| 7921 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7925 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7926 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7927 | MockRead data_reads[] = { |
| 7928 | // A part of the response body is received with the response headers. |
| 7929 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7930 | // The rest of the response body is received in two parts. |
| 7931 | MockRead("lo"), |
| 7932 | MockRead(" world"), |
| 7933 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7934 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7935 | }; |
| 7936 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7937 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7940 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7944 | |
| 7945 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7946 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7948 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7949 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7950 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7951 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7952 | std::string status_line = response->headers->GetStatusLine(); |
| 7953 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7954 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7955 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7956 | |
| 7957 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7958 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7960 | EXPECT_EQ("hello world", response_data); |
| 7961 | |
| 7962 | // Empty the current queue. This is necessary because idle sockets are |
| 7963 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7964 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7965 | |
| 7966 | // 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] | 7967 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7968 | } |
| 7969 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7970 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7971 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7972 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7973 | HttpRequestInfo request; |
| 7974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7975 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7976 | request.traffic_annotation = |
| 7977 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7978 | |
| 7979 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7980 | MockWrite( |
| 7981 | "GET / HTTP/1.1\r\n" |
| 7982 | "Host: www.example.org\r\n" |
| 7983 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7984 | }; |
| 7985 | |
| 7986 | MockRead data_reads[] = { |
| 7987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7988 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7989 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7990 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | }; |
| 7992 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7993 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7995 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7996 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7999 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8005 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8007 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8009 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8010 | ASSERT_TRUE(response); |
| 8011 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8012 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8013 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8014 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | |
| 8016 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8017 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8018 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8019 | EXPECT_EQ("hello world", response_data); |
| 8020 | |
| 8021 | // Empty the current queue. This is necessary because idle sockets are |
| 8022 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8023 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8024 | |
| 8025 | // 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] | 8026 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8027 | } |
| 8028 | |
| 8029 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8030 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8031 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8032 | HttpRequestInfo request; |
| 8033 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8034 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8035 | request.traffic_annotation = |
| 8036 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8037 | |
| 8038 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8039 | MockWrite( |
| 8040 | "GET / HTTP/1.1\r\n" |
| 8041 | "Host: www.example.org\r\n" |
| 8042 | "Connection: keep-alive\r\n\r\n"), |
| 8043 | MockWrite( |
| 8044 | "GET / HTTP/1.1\r\n" |
| 8045 | "Host: www.example.org\r\n" |
| 8046 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8047 | }; |
| 8048 | |
| 8049 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8050 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8051 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8052 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8053 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8054 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8057 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8058 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8059 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8061 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8063 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8064 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8066 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8067 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8068 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8069 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8070 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8072 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8073 | |
| 8074 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8075 | ASSERT_TRUE(response); |
| 8076 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8077 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8078 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8079 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | |
| 8081 | std::string response_data; |
| 8082 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8084 | EXPECT_EQ("hello world", response_data); |
| 8085 | |
| 8086 | // Empty the current queue. This is necessary because idle sockets are |
| 8087 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8088 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8089 | |
| 8090 | // 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] | 8091 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8092 | |
| 8093 | // Now start the second transaction, which should reuse the previous socket. |
| 8094 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8095 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8096 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8097 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8098 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8099 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8101 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8102 | |
| 8103 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8104 | ASSERT_TRUE(response); |
| 8105 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8106 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8107 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8108 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8109 | |
| 8110 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8112 | EXPECT_EQ("hello world", response_data); |
| 8113 | |
| 8114 | // Empty the current queue. This is necessary because idle sockets are |
| 8115 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8116 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8117 | |
| 8118 | // 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] | 8119 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8120 | } |
| 8121 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8122 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8123 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8124 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8125 | HttpRequestInfo request; |
| 8126 | request.method = "GET"; |
| 8127 | request.url = GURL("http://www.example.org/"); |
| 8128 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8129 | request.traffic_annotation = |
| 8130 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8131 | |
| 8132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8135 | |
| 8136 | MockRead data_reads[] = { |
| 8137 | // A part of the response body is received with the response headers. |
| 8138 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8139 | // The rest of the response body is received in two parts. |
| 8140 | MockRead("lo"), MockRead(" world"), |
| 8141 | MockRead("junk"), // Should not be read!! |
| 8142 | MockRead(SYNCHRONOUS, OK), |
| 8143 | }; |
| 8144 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8145 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8147 | |
| 8148 | TestCompletionCallback callback; |
| 8149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8150 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8152 | |
| 8153 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8155 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8156 | ASSERT_TRUE(response); |
| 8157 | EXPECT_TRUE(response->headers); |
| 8158 | std::string status_line = response->headers->GetStatusLine(); |
| 8159 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8160 | |
| 8161 | // Make memory critical notification and ensure the transaction still has been |
| 8162 | // operating right. |
| 8163 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8164 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8165 | base::RunLoop().RunUntilIdle(); |
| 8166 | |
| 8167 | // Socket should not be flushed as long as it is not idle. |
| 8168 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8169 | |
| 8170 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8171 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8172 | EXPECT_THAT(rv, IsOk()); |
| 8173 | EXPECT_EQ("hello world", response_data); |
| 8174 | |
| 8175 | // Empty the current queue. This is necessary because idle sockets are |
| 8176 | // added to the connection pool asynchronously with a PostTask. |
| 8177 | base::RunLoop().RunUntilIdle(); |
| 8178 | |
| 8179 | // We now check to make sure the socket was added back to the pool. |
| 8180 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8181 | |
| 8182 | // Idle sockets should be flushed now. |
| 8183 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8184 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8185 | base::RunLoop().RunUntilIdle(); |
| 8186 | |
| 8187 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8188 | } |
| 8189 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8190 | // Disable idle socket closing on memory pressure. |
| 8191 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8192 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8193 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8194 | HttpRequestInfo request; |
| 8195 | request.method = "GET"; |
| 8196 | request.url = GURL("http://www.example.org/"); |
| 8197 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8198 | request.traffic_annotation = |
| 8199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8200 | |
| 8201 | // Disable idle socket closing on memory pressure. |
| 8202 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8204 | |
| 8205 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8206 | |
| 8207 | MockRead data_reads[] = { |
| 8208 | // A part of the response body is received with the response headers. |
| 8209 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8210 | // The rest of the response body is received in two parts. |
| 8211 | MockRead("lo"), MockRead(" world"), |
| 8212 | MockRead("junk"), // Should not be read!! |
| 8213 | MockRead(SYNCHRONOUS, OK), |
| 8214 | }; |
| 8215 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8216 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8217 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8218 | |
| 8219 | TestCompletionCallback callback; |
| 8220 | |
| 8221 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8223 | |
| 8224 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8225 | |
| 8226 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8227 | ASSERT_TRUE(response); |
| 8228 | EXPECT_TRUE(response->headers); |
| 8229 | std::string status_line = response->headers->GetStatusLine(); |
| 8230 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8231 | |
| 8232 | // Make memory critical notification and ensure the transaction still has been |
| 8233 | // operating right. |
| 8234 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8235 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8236 | base::RunLoop().RunUntilIdle(); |
| 8237 | |
| 8238 | // Socket should not be flushed as long as it is not idle. |
| 8239 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8240 | |
| 8241 | std::string response_data; |
| 8242 | rv = ReadTransaction(&trans, &response_data); |
| 8243 | EXPECT_THAT(rv, IsOk()); |
| 8244 | EXPECT_EQ("hello world", response_data); |
| 8245 | |
| 8246 | // Empty the current queue. This is necessary because idle sockets are |
| 8247 | // added to the connection pool asynchronously with a PostTask. |
| 8248 | base::RunLoop().RunUntilIdle(); |
| 8249 | |
| 8250 | // We now check to make sure the socket was added back to the pool. |
| 8251 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8252 | |
| 8253 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8254 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8255 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8256 | base::RunLoop().RunUntilIdle(); |
| 8257 | |
| 8258 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8259 | |
| 8260 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8261 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8262 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8263 | base::RunLoop().RunUntilIdle(); |
| 8264 | |
| 8265 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8266 | } |
| 8267 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8268 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8269 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8270 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8271 | HttpRequestInfo request; |
| 8272 | request.method = "GET"; |
| 8273 | request.url = GURL("https://www.example.org/"); |
| 8274 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8275 | request.traffic_annotation = |
| 8276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8277 | |
| 8278 | MockWrite data_writes[] = { |
| 8279 | MockWrite("GET / HTTP/1.1\r\n" |
| 8280 | "Host: www.example.org\r\n" |
| 8281 | "Connection: keep-alive\r\n\r\n"), |
| 8282 | }; |
| 8283 | |
| 8284 | MockRead data_reads[] = { |
| 8285 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8286 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8287 | |
| 8288 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8290 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8291 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8293 | |
| 8294 | TestCompletionCallback callback; |
| 8295 | |
| 8296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8298 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8299 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8300 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8301 | |
| 8302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8305 | ASSERT_TRUE(response); |
| 8306 | ASSERT_TRUE(response->headers); |
| 8307 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8308 | |
| 8309 | // Make memory critical notification and ensure the transaction still has been |
| 8310 | // operating right. |
| 8311 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8312 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8313 | base::RunLoop().RunUntilIdle(); |
| 8314 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8315 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8316 | |
| 8317 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8318 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8319 | EXPECT_THAT(rv, IsOk()); |
| 8320 | EXPECT_EQ("hello world", response_data); |
| 8321 | |
| 8322 | // Empty the current queue. This is necessary because idle sockets are |
| 8323 | // added to the connection pool asynchronously with a PostTask. |
| 8324 | base::RunLoop().RunUntilIdle(); |
| 8325 | |
| 8326 | // 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] | 8327 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8328 | |
| 8329 | // Make memory notification once again and ensure idle socket is closed. |
| 8330 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8331 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8332 | base::RunLoop().RunUntilIdle(); |
| 8333 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8334 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8335 | } |
| 8336 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8337 | // Make sure that we recycle a socket after a zero-length response. |
| 8338 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8339 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8340 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8342 | request.url = GURL( |
| 8343 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8344 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8345 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8346 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8347 | request.traffic_annotation = |
| 8348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8351 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8352 | MockRead data_reads[] = { |
| 8353 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8354 | "Content-Length: 0\r\n" |
| 8355 | "Content-Type: text/html\r\n\r\n"), |
| 8356 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8357 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8358 | }; |
| 8359 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8360 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8362 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8363 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8364 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8365 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8367 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8371 | |
| 8372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8375 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8376 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8377 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8378 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8379 | std::string status_line = response->headers->GetStatusLine(); |
| 8380 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8381 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8382 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8383 | |
| 8384 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8385 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8386 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8387 | EXPECT_EQ("", response_data); |
| 8388 | |
| 8389 | // Empty the current queue. This is necessary because idle sockets are |
| 8390 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8391 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8392 | |
| 8393 | // 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] | 8394 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8395 | } |
| 8396 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8397 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8398 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8399 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8400 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8401 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8402 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8403 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8404 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8405 | // after use. |
| 8406 | request[0].method = "GET"; |
| 8407 | request[0].url = GURL("http://www.google.com/"); |
| 8408 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8409 | request[0].traffic_annotation = |
| 8410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8411 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8412 | // transaction 1. The first attempts fails when writing the POST data. |
| 8413 | // This causes the transaction to retry with a new socket. The second |
| 8414 | // attempt succeeds. |
| 8415 | request[1].method = "POST"; |
| 8416 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8417 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8418 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8419 | request[1].traffic_annotation = |
| 8420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8421 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8423 | |
| 8424 | // The first socket is used for transaction 1 and the first attempt of |
| 8425 | // transaction 2. |
| 8426 | |
| 8427 | // The response of transaction 1. |
| 8428 | MockRead data_reads1[] = { |
| 8429 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8430 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8432 | }; |
| 8433 | // The mock write results of transaction 1 and the first attempt of |
| 8434 | // transaction 2. |
| 8435 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8436 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8437 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8438 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8439 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8440 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8441 | |
| 8442 | // The second socket is used for the second attempt of transaction 2. |
| 8443 | |
| 8444 | // The response of transaction 2. |
| 8445 | MockRead data_reads2[] = { |
| 8446 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8447 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8448 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8449 | }; |
| 8450 | // The mock write results of the second attempt of transaction 2. |
| 8451 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8452 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8453 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8454 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8455 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8456 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8458 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8459 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8460 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8461 | "hello world", "welcome" |
| 8462 | }; |
| 8463 | |
| 8464 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8467 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8469 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8471 | |
| 8472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8475 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8476 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8477 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8478 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8479 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8480 | |
| 8481 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8482 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8484 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8485 | } |
| 8486 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8487 | |
| 8488 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8489 | // 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] | 8490 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8491 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8492 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8494 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8495 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8496 | request.traffic_annotation = |
| 8497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8501 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8502 | // The password contains an escaped character -- for this test to pass it |
| 8503 | // will need to be unescaped by HttpNetworkTransaction. |
| 8504 | EXPECT_EQ("b%40r", request.url.password()); |
| 8505 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8506 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8507 | MockWrite( |
| 8508 | "GET / HTTP/1.1\r\n" |
| 8509 | "Host: www.example.org\r\n" |
| 8510 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8511 | }; |
| 8512 | |
| 8513 | MockRead data_reads1[] = { |
| 8514 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8515 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8516 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8517 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8518 | }; |
| 8519 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8520 | // After the challenge above, the transaction will be restarted using the |
| 8521 | // identity from the url (foo, b@r) to answer the challenge. |
| 8522 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8523 | MockWrite( |
| 8524 | "GET / HTTP/1.1\r\n" |
| 8525 | "Host: www.example.org\r\n" |
| 8526 | "Connection: keep-alive\r\n" |
| 8527 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8528 | }; |
| 8529 | |
| 8530 | MockRead data_reads2[] = { |
| 8531 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8532 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8533 | MockRead(SYNCHRONOUS, OK), |
| 8534 | }; |
| 8535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8536 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8537 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8538 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8539 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8541 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8542 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8544 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8545 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8546 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8547 | |
| 8548 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8549 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8551 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8552 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8553 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8555 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8556 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8557 | |
| 8558 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8559 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8560 | |
| 8561 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8562 | |
| 8563 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8564 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8565 | } |
| 8566 | |
| 8567 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8568 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8569 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8570 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8571 | HttpRequestInfo request; |
| 8572 | request.method = "GET"; |
| 8573 | // Note: the URL has a username:password in it. The password "baz" is |
| 8574 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8575 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8576 | |
| 8577 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8578 | request.traffic_annotation = |
| 8579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8580 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8582 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8583 | |
| 8584 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8585 | MockWrite( |
| 8586 | "GET / HTTP/1.1\r\n" |
| 8587 | "Host: www.example.org\r\n" |
| 8588 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8589 | }; |
| 8590 | |
| 8591 | MockRead data_reads1[] = { |
| 8592 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8593 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8594 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8595 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8596 | }; |
| 8597 | |
| 8598 | // After the challenge above, the transaction will be restarted using the |
| 8599 | // identity from the url (foo, baz) to answer the challenge. |
| 8600 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8601 | MockWrite( |
| 8602 | "GET / HTTP/1.1\r\n" |
| 8603 | "Host: www.example.org\r\n" |
| 8604 | "Connection: keep-alive\r\n" |
| 8605 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8606 | }; |
| 8607 | |
| 8608 | MockRead data_reads2[] = { |
| 8609 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8610 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8611 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8612 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8613 | }; |
| 8614 | |
| 8615 | // After the challenge above, the transaction will be restarted using the |
| 8616 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8617 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8618 | MockWrite( |
| 8619 | "GET / HTTP/1.1\r\n" |
| 8620 | "Host: www.example.org\r\n" |
| 8621 | "Connection: keep-alive\r\n" |
| 8622 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8623 | }; |
| 8624 | |
| 8625 | MockRead data_reads3[] = { |
| 8626 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8627 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8628 | MockRead(SYNCHRONOUS, OK), |
| 8629 | }; |
| 8630 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8631 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8632 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8633 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8634 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8635 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8636 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8637 | |
| 8638 | TestCompletionCallback callback1; |
| 8639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8640 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8642 | |
| 8643 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8646 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8647 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8651 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8652 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8655 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8656 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8657 | |
| 8658 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8661 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8662 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8663 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8664 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8665 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8666 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8667 | |
| 8668 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8669 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8670 | |
| 8671 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8672 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8673 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8674 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8675 | } |
| 8676 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8677 | |
| 8678 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8679 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8680 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8681 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8682 | HttpRequestInfo request; |
| 8683 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8684 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8685 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8686 | request.traffic_annotation = |
| 8687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8691 | |
| 8692 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8693 | MockWrite( |
| 8694 | "GET / HTTP/1.1\r\n" |
| 8695 | "Host: www.example.org\r\n" |
| 8696 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8697 | }; |
| 8698 | |
| 8699 | MockRead data_reads1[] = { |
| 8700 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8701 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8702 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8703 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8704 | }; |
| 8705 | |
| 8706 | // After the challenge above, the transaction will be restarted using the |
| 8707 | // identity supplied by the user, not the one in the URL, to answer the |
| 8708 | // challenge. |
| 8709 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8710 | MockWrite( |
| 8711 | "GET / HTTP/1.1\r\n" |
| 8712 | "Host: www.example.org\r\n" |
| 8713 | "Connection: keep-alive\r\n" |
| 8714 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8715 | }; |
| 8716 | |
| 8717 | MockRead data_reads3[] = { |
| 8718 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8719 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8720 | MockRead(SYNCHRONOUS, OK), |
| 8721 | }; |
| 8722 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8723 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8724 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8725 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8726 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8727 | |
| 8728 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8729 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8731 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8732 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8733 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8735 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8736 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8737 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8738 | |
| 8739 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8740 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8742 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8743 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8744 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8746 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8747 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8748 | |
| 8749 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8750 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8751 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8752 | |
| 8753 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8754 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8755 | } |
| 8756 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8757 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8758 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8760 | |
| 8761 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8762 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8763 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8765 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8766 | request.traffic_annotation = |
| 8767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8770 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8771 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8772 | MockWrite( |
| 8773 | "GET /x/y/z HTTP/1.1\r\n" |
| 8774 | "Host: www.example.org\r\n" |
| 8775 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8776 | }; |
| 8777 | |
| 8778 | MockRead data_reads1[] = { |
| 8779 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8780 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8781 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8782 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8783 | }; |
| 8784 | |
| 8785 | // Resend with authorization (username=foo, password=bar) |
| 8786 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8787 | MockWrite( |
| 8788 | "GET /x/y/z HTTP/1.1\r\n" |
| 8789 | "Host: www.example.org\r\n" |
| 8790 | "Connection: keep-alive\r\n" |
| 8791 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8792 | }; |
| 8793 | |
| 8794 | // Sever accepts the authorization. |
| 8795 | MockRead data_reads2[] = { |
| 8796 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8797 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8798 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8799 | }; |
| 8800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8801 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8802 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8803 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8804 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8806 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8807 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8808 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8810 | |
| 8811 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8812 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8814 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8815 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8816 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8818 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8820 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8821 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8823 | |
| 8824 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8827 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8828 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8829 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8830 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8831 | } |
| 8832 | |
| 8833 | // ------------------------------------------------------------------------ |
| 8834 | |
| 8835 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8836 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8837 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8838 | request.method = "GET"; |
| 8839 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8840 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8841 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8842 | request.traffic_annotation = |
| 8843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8846 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8847 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | MockWrite( |
| 8849 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8850 | "Host: www.example.org\r\n" |
| 8851 | "Connection: keep-alive\r\n" |
| 8852 | // Send preemptive authorization for MyRealm1 |
| 8853 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8854 | }; |
| 8855 | |
| 8856 | // The server didn't like the preemptive authorization, and |
| 8857 | // challenges us for a different realm (MyRealm2). |
| 8858 | MockRead data_reads1[] = { |
| 8859 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8860 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8861 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8862 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8863 | }; |
| 8864 | |
| 8865 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8866 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8867 | MockWrite( |
| 8868 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8869 | "Host: www.example.org\r\n" |
| 8870 | "Connection: keep-alive\r\n" |
| 8871 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8872 | }; |
| 8873 | |
| 8874 | // Sever accepts the authorization. |
| 8875 | MockRead data_reads2[] = { |
| 8876 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8877 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8878 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8879 | }; |
| 8880 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8881 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8882 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8884 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8885 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8886 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8887 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8888 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8889 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8890 | |
| 8891 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8893 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8894 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8895 | ASSERT_TRUE(response); |
| 8896 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8897 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8898 | EXPECT_EQ("http://www.example.org", |
| 8899 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8900 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8901 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8903 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8905 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8906 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8908 | |
| 8909 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8910 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8912 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8913 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8914 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8915 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8916 | } |
| 8917 | |
| 8918 | // ------------------------------------------------------------------------ |
| 8919 | |
| 8920 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8921 | // succeed with preemptive authorization. |
| 8922 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8923 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8924 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8925 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8926 | request.traffic_annotation = |
| 8927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8929 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8930 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8932 | MockWrite( |
| 8933 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8934 | "Host: www.example.org\r\n" |
| 8935 | "Connection: keep-alive\r\n" |
| 8936 | // The authorization for MyRealm1 gets sent preemptively |
| 8937 | // (since the url is in the same protection space) |
| 8938 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8939 | }; |
| 8940 | |
| 8941 | // Sever accepts the preemptive authorization |
| 8942 | MockRead data_reads1[] = { |
| 8943 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8944 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8946 | }; |
| 8947 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8948 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8950 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8951 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8952 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8953 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | |
| 8956 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8957 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8959 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8960 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8961 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8962 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8963 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8964 | } |
| 8965 | |
| 8966 | // ------------------------------------------------------------------------ |
| 8967 | |
| 8968 | // Transaction 4: request another URL in MyRealm (however the |
| 8969 | // url is not known to belong to the protection space, so no pre-auth). |
| 8970 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8971 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8972 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8973 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8974 | request.traffic_annotation = |
| 8975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8978 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8980 | MockWrite( |
| 8981 | "GET /x/1 HTTP/1.1\r\n" |
| 8982 | "Host: www.example.org\r\n" |
| 8983 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8984 | }; |
| 8985 | |
| 8986 | MockRead data_reads1[] = { |
| 8987 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8988 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8989 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8990 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8991 | }; |
| 8992 | |
| 8993 | // Resend with authorization from MyRealm's cache. |
| 8994 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8995 | MockWrite( |
| 8996 | "GET /x/1 HTTP/1.1\r\n" |
| 8997 | "Host: www.example.org\r\n" |
| 8998 | "Connection: keep-alive\r\n" |
| 8999 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9000 | }; |
| 9001 | |
| 9002 | // Sever accepts the authorization. |
| 9003 | MockRead data_reads2[] = { |
| 9004 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9005 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9006 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9007 | }; |
| 9008 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9009 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9010 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9011 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9012 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9014 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9015 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9016 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9018 | |
| 9019 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9020 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9022 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9023 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9024 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9026 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9027 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9028 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9030 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9031 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9032 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9033 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9034 | } |
| 9035 | |
| 9036 | // ------------------------------------------------------------------------ |
| 9037 | |
| 9038 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9039 | // cached identity. Should invalidate and re-prompt. |
| 9040 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9041 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9042 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9043 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9044 | request.traffic_annotation = |
| 9045 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9047 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9048 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9049 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9050 | MockWrite( |
| 9051 | "GET /p/q/t HTTP/1.1\r\n" |
| 9052 | "Host: www.example.org\r\n" |
| 9053 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9054 | }; |
| 9055 | |
| 9056 | MockRead data_reads1[] = { |
| 9057 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9058 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9059 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9060 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9061 | }; |
| 9062 | |
| 9063 | // Resend with authorization from cache for MyRealm. |
| 9064 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9065 | MockWrite( |
| 9066 | "GET /p/q/t HTTP/1.1\r\n" |
| 9067 | "Host: www.example.org\r\n" |
| 9068 | "Connection: keep-alive\r\n" |
| 9069 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9070 | }; |
| 9071 | |
| 9072 | // Sever rejects the authorization. |
| 9073 | MockRead data_reads2[] = { |
| 9074 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9075 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9076 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9077 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9078 | }; |
| 9079 | |
| 9080 | // At this point we should prompt for new credentials for MyRealm. |
| 9081 | // Restart with username=foo3, password=foo4. |
| 9082 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9083 | MockWrite( |
| 9084 | "GET /p/q/t HTTP/1.1\r\n" |
| 9085 | "Host: www.example.org\r\n" |
| 9086 | "Connection: keep-alive\r\n" |
| 9087 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9088 | }; |
| 9089 | |
| 9090 | // Sever accepts the authorization. |
| 9091 | MockRead data_reads3[] = { |
| 9092 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9093 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9094 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9095 | }; |
| 9096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9097 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9098 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9099 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9100 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9101 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9102 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9104 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9106 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9108 | |
| 9109 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9112 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9113 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9114 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9116 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9118 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9119 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9120 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9121 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9122 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9124 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9126 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9127 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9129 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9130 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9131 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9133 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9134 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9135 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9136 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9137 | } |
| 9138 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9139 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9140 | // Tests that nonce count increments when multiple auth attempts |
| 9141 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9142 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9143 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9144 | new HttpAuthHandlerDigest::Factory(); |
| 9145 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9146 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9147 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9148 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9150 | |
| 9151 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9152 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9153 | HttpRequestInfo request; |
| 9154 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9155 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9156 | request.traffic_annotation = |
| 9157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9160 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9161 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9162 | MockWrite( |
| 9163 | "GET /x/y/z HTTP/1.1\r\n" |
| 9164 | "Host: www.example.org\r\n" |
| 9165 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9166 | }; |
| 9167 | |
| 9168 | MockRead data_reads1[] = { |
| 9169 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9170 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9171 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9172 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9173 | }; |
| 9174 | |
| 9175 | // Resend with authorization (username=foo, password=bar) |
| 9176 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9177 | MockWrite( |
| 9178 | "GET /x/y/z HTTP/1.1\r\n" |
| 9179 | "Host: www.example.org\r\n" |
| 9180 | "Connection: keep-alive\r\n" |
| 9181 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9182 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9183 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9184 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9185 | }; |
| 9186 | |
| 9187 | // Sever accepts the authorization. |
| 9188 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9189 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9190 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9191 | }; |
| 9192 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9193 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9194 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9195 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9196 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9198 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9199 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9200 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9202 | |
| 9203 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9204 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9206 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9207 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9208 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9210 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9212 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9213 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9215 | |
| 9216 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9219 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9220 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9221 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9222 | } |
| 9223 | |
| 9224 | // ------------------------------------------------------------------------ |
| 9225 | |
| 9226 | // Transaction 2: Request another resource in digestive's protection space. |
| 9227 | // This will preemptively add an Authorization header which should have an |
| 9228 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9229 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9230 | HttpRequestInfo request; |
| 9231 | request.method = "GET"; |
| 9232 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9233 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9234 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9235 | request.traffic_annotation = |
| 9236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9238 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9239 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9240 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9241 | MockWrite( |
| 9242 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9243 | "Host: www.example.org\r\n" |
| 9244 | "Connection: keep-alive\r\n" |
| 9245 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9246 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9247 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9248 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9249 | }; |
| 9250 | |
| 9251 | // Sever accepts the authorization. |
| 9252 | MockRead data_reads1[] = { |
| 9253 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9254 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9255 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9256 | }; |
| 9257 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9258 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9261 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9262 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9263 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9265 | |
| 9266 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9269 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9270 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9271 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9272 | } |
| 9273 | } |
| 9274 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9275 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9276 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9277 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9279 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9280 | |
| 9281 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9282 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9283 | trans.read_buf_len_ = 15; |
| 9284 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9285 | |
| 9286 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9287 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9288 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9289 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9290 | response->response_time = base::Time::Now(); |
| 9291 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9292 | |
| 9293 | { // Setup state for response_.vary_data |
| 9294 | HttpRequestInfo request; |
| 9295 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9296 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9297 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9298 | request.extra_headers.SetHeader("Foo", "1"); |
| 9299 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9300 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9301 | } |
| 9302 | |
| 9303 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9304 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9305 | |
| 9306 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9307 | EXPECT_FALSE(trans.read_buf_); |
| 9308 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9309 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9310 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9311 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9312 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9313 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9314 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9315 | } |
| 9316 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9317 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9318 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9319 | HttpRequestInfo request; |
| 9320 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9321 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9322 | request.traffic_annotation = |
| 9323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9327 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9328 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9329 | MockWrite( |
| 9330 | "GET / HTTP/1.1\r\n" |
| 9331 | "Host: www.example.org\r\n" |
| 9332 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9333 | }; |
| 9334 | |
| 9335 | MockRead data_reads[] = { |
| 9336 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9337 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9338 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9339 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9340 | }; |
| 9341 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9342 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9343 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9344 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9345 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9346 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9347 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9348 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9352 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9356 | |
| 9357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9358 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9360 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9361 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9362 | |
| 9363 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9366 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9367 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9368 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9369 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9370 | } |
| 9371 | |
| 9372 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9373 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9374 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9375 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9376 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9377 | |
| 9378 | HttpRequestInfo request; |
| 9379 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9380 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9381 | request.traffic_annotation = |
| 9382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9383 | |
| 9384 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9385 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9386 | "Host: www.example.org:443\r\n" |
| 9387 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9388 | }; |
| 9389 | |
| 9390 | MockRead proxy_reads[] = { |
| 9391 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9392 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9393 | }; |
| 9394 | |
| 9395 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9396 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9397 | "Host: www.example.org:443\r\n" |
| 9398 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9399 | MockWrite("GET / HTTP/1.1\r\n" |
| 9400 | "Host: www.example.org\r\n" |
| 9401 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9402 | }; |
| 9403 | |
| 9404 | MockRead data_reads[] = { |
| 9405 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9406 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9407 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9408 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9409 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9410 | }; |
| 9411 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9412 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9413 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9414 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9415 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9416 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9417 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9418 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9422 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9423 | |
| 9424 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9425 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9430 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9432 | |
| 9433 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9434 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9436 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9438 | |
| 9439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9442 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9443 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9444 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9445 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9446 | } |
| 9447 | } |
| 9448 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9449 | |
| 9450 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9451 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9452 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9453 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9454 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9455 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9456 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9457 | |
| 9458 | HttpRequestInfo request; |
| 9459 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9460 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9461 | request.traffic_annotation = |
| 9462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9463 | |
| 9464 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9465 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9466 | "Host: www.example.org:443\r\n" |
| 9467 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9468 | MockWrite("GET / HTTP/1.1\r\n" |
| 9469 | "Host: www.example.org\r\n" |
| 9470 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9471 | }; |
| 9472 | |
| 9473 | MockRead data_reads[] = { |
| 9474 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9475 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9476 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9477 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9478 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9479 | }; |
| 9480 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9481 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9482 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9483 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9484 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9485 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9486 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9489 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9490 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9492 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9493 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9494 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9495 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9496 | |
| 9497 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9498 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9499 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9500 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9501 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9502 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9503 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9504 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9505 | EXPECT_EQ(200, response->headers->response_code()); |
| 9506 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9507 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9508 | |
| 9509 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9510 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9511 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9512 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9513 | } |
| 9514 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9515 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9516 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9517 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9518 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9519 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9520 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9521 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9522 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9523 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9524 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9525 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9526 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9527 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9529 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9530 | request.traffic_annotation = |
| 9531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9532 | |
| 9533 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9534 | MockWrite(ASYNC, 0, |
| 9535 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9536 | "Host: www.example.org:443\r\n" |
| 9537 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9538 | }; |
| 9539 | |
| 9540 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9541 | // Pause on first read. |
| 9542 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9543 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9544 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9545 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9546 | }; |
| 9547 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9548 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9549 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9550 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9551 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9554 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9557 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9558 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9559 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9561 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9562 | |
| 9563 | // Host resolution takes |kTimeIncrement|. |
| 9564 | FastForwardBy(kTimeIncrement); |
| 9565 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9566 | // request to instantly complete, and the async connect will start as well. |
| 9567 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9568 | |
| 9569 | // Connecting takes |kTimeIncrement|. |
| 9570 | FastForwardBy(kTimeIncrement); |
| 9571 | data.RunUntilPaused(); |
| 9572 | |
| 9573 | // The server takes |kTimeIncrement| to respond. |
| 9574 | FastForwardBy(kTimeIncrement); |
| 9575 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9576 | |
| 9577 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9578 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9579 | } |
| 9580 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9581 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9582 | TEST_F(HttpNetworkTransactionTest, |
| 9583 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9584 | base::HistogramTester histograms; |
| 9585 | session_deps_.proxy_resolution_service = |
| 9586 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9587 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9588 | TestNetLog net_log; |
| 9589 | session_deps_.net_log = &net_log; |
| 9590 | |
| 9591 | HttpRequestInfo request; |
| 9592 | request.method = "GET"; |
| 9593 | request.url = GURL("https://www.example.org/"); |
| 9594 | request.traffic_annotation = |
| 9595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9596 | |
| 9597 | MockWrite data_writes[] = { |
| 9598 | MockWrite(ASYNC, 0, |
| 9599 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9600 | "Host: www.example.org:443\r\n" |
| 9601 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9602 | }; |
| 9603 | |
| 9604 | MockRead data_reads[] = { |
| 9605 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9606 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9607 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9608 | }; |
| 9609 | |
| 9610 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9611 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9612 | |
| 9613 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9615 | |
| 9616 | TestCompletionCallback callback; |
| 9617 | |
| 9618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9619 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9620 | |
| 9621 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9622 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9623 | |
| 9624 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9625 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9626 | } |
| 9627 | |
| 9628 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9629 | // request for main frames. |
| 9630 | TEST_F(HttpNetworkTransactionTest, |
| 9631 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9632 | base::HistogramTester histograms; |
| 9633 | session_deps_.proxy_resolution_service = |
| 9634 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9635 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9636 | TestNetLog net_log; |
| 9637 | session_deps_.net_log = &net_log; |
| 9638 | |
| 9639 | HttpRequestInfo request; |
| 9640 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9641 | request.method = "GET"; |
| 9642 | request.url = GURL("https://www.example.org/"); |
| 9643 | request.traffic_annotation = |
| 9644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9645 | |
| 9646 | MockWrite data_writes[] = { |
| 9647 | MockWrite(ASYNC, 0, |
| 9648 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9649 | "Host: www.example.org:443\r\n" |
| 9650 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9651 | }; |
| 9652 | |
| 9653 | MockRead data_reads[] = { |
| 9654 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9655 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9656 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9657 | }; |
| 9658 | |
| 9659 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9660 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9661 | |
| 9662 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9664 | |
| 9665 | TestCompletionCallback callback; |
| 9666 | |
| 9667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9668 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9669 | |
| 9670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9672 | |
| 9673 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9674 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9675 | } |
| 9676 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9677 | // 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] | 9678 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9679 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9680 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9681 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9682 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9683 | TestNetLog net_log; |
| 9684 | session_deps_.net_log = &net_log; |
| 9685 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9686 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9687 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9688 | |
| 9689 | HttpRequestInfo request; |
| 9690 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9691 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9692 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9693 | request.traffic_annotation = |
| 9694 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9695 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9696 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9697 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9698 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9699 | spdy::SpdySerializedFrame goaway( |
| 9700 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9701 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9702 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9703 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9704 | }; |
| 9705 | |
| 9706 | static const char* const kExtraHeaders[] = { |
| 9707 | "location", |
| 9708 | "http://login.example.com/", |
| 9709 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9710 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9711 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9712 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9713 | // Pause on first read. |
| 9714 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9715 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9716 | }; |
| 9717 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9718 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9719 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9720 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9721 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9722 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9724 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9725 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9729 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9730 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9732 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9733 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9734 | // Host resolution takes |kTimeIncrement|. |
| 9735 | FastForwardBy(kTimeIncrement); |
| 9736 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9737 | // request to instantly complete, and the async connect will start as well. |
| 9738 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9739 | |
| 9740 | // Connecting takes |kTimeIncrement|. |
| 9741 | FastForwardBy(kTimeIncrement); |
| 9742 | data.RunUntilPaused(); |
| 9743 | |
| 9744 | FastForwardBy(kTimeIncrement); |
| 9745 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9746 | rv = callback.WaitForResult(); |
Eric Roman | 96c5b29 | 2019-04-23 18:04:59 | [diff] [blame] | 9747 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | } |
| 9749 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9750 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9751 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9752 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9753 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9754 | |
| 9755 | HttpRequestInfo request; |
| 9756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9757 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9758 | request.traffic_annotation = |
| 9759 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9760 | |
| 9761 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9762 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9763 | "Host: www.example.org:443\r\n" |
| 9764 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9765 | }; |
| 9766 | |
| 9767 | MockRead data_reads[] = { |
| 9768 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9769 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9770 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9771 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9772 | }; |
| 9773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9774 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9775 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9776 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9777 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9778 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9780 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9787 | |
| 9788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9789 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9790 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9791 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9792 | } |
| 9793 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9794 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9795 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9796 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9797 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9798 | |
| 9799 | HttpRequestInfo request; |
| 9800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9801 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9802 | request.traffic_annotation = |
| 9803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9804 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9805 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9806 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9807 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9808 | spdy::SpdySerializedFrame rst( |
| 9809 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9810 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9811 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9812 | }; |
| 9813 | |
| 9814 | static const char* const kExtraHeaders[] = { |
| 9815 | "location", |
| 9816 | "http://login.example.com/", |
| 9817 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9818 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9819 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9820 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9821 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9822 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9823 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9824 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9825 | }; |
| 9826 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9827 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9828 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9829 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9830 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9831 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9832 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9834 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9835 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9841 | |
| 9842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9843 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9844 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9845 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9846 | } |
| 9847 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9848 | // Test the request-challenge-retry sequence for basic auth, through |
| 9849 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9850 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9851 | HttpRequestInfo request; |
| 9852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9853 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9854 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9855 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9856 | request.traffic_annotation = |
| 9857 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9858 | |
| 9859 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9860 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9861 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9862 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9863 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9864 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9866 | |
| 9867 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9868 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9869 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9870 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9871 | spdy::SpdySerializedFrame rst( |
| 9872 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9873 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9875 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9876 | // be issuing -- the final header line contains the credentials. |
| 9877 | const char* const kAuthCredentials[] = { |
| 9878 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9879 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9880 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9881 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9882 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9883 | HostPortPair("www.example.org", 443))); |
| 9884 | // fetch https://www.example.org/ via HTTP |
| 9885 | const char get[] = |
| 9886 | "GET / HTTP/1.1\r\n" |
| 9887 | "Host: www.example.org\r\n" |
| 9888 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9889 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9890 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9891 | |
| 9892 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9893 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9894 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9895 | }; |
| 9896 | |
| 9897 | // The proxy responds to the connect with a 407, using a persistent |
| 9898 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9899 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9900 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9901 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9902 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9903 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9904 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9905 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9906 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9907 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9908 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9909 | "Content-Length: 5\r\n\r\n"; |
| 9910 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9911 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9912 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9913 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9914 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9915 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9916 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9917 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9918 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9919 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9920 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9921 | }; |
| 9922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9923 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9924 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9925 | // Negotiate SPDY to the proxy |
| 9926 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9927 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9928 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9929 | // Vanilla SSL to the server |
| 9930 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9932 | |
| 9933 | TestCompletionCallback callback1; |
| 9934 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9935 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9936 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9937 | |
| 9938 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9940 | |
| 9941 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9942 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9943 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9944 | log.GetEntries(&entries); |
| 9945 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9946 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9947 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9948 | ExpectLogContainsSomewhere( |
| 9949 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9950 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9951 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9952 | |
| 9953 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9954 | ASSERT_TRUE(response); |
| 9955 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9956 | EXPECT_EQ(407, response->headers->response_code()); |
| 9957 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9958 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 9959 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9960 | |
| 9961 | TestCompletionCallback callback2; |
| 9962 | |
| 9963 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9964 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9966 | |
| 9967 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9968 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9969 | |
| 9970 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9971 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9972 | |
| 9973 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9974 | EXPECT_EQ(200, response->headers->response_code()); |
| 9975 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9976 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9977 | |
| 9978 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9979 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9980 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9981 | LoadTimingInfo load_timing_info; |
| 9982 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9983 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9984 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9985 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9986 | trans.reset(); |
| 9987 | session->CloseAllConnections(); |
| 9988 | } |
| 9989 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9990 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9991 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9992 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9993 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9994 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9995 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9996 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9997 | HttpRequestInfo request; |
| 9998 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9999 | request.traffic_annotation = |
| 10000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10001 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10002 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10003 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10004 | push_request.method = "GET"; |
| 10005 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10006 | push_request.traffic_annotation = |
| 10007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10008 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10009 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10010 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10011 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10012 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10013 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10014 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10015 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10016 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10017 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10020 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10021 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10022 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10023 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10024 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10025 | |
| 10026 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10027 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10028 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10029 | }; |
| 10030 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10031 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10032 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10033 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10034 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10035 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10036 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10037 | spdy::SpdySerializedFrame stream1_body( |
| 10038 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10039 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10040 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10041 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10042 | |
| 10043 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10044 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10045 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10046 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10047 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10048 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10049 | }; |
| 10050 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10051 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10052 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10053 | // Negotiate SPDY to the proxy |
| 10054 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10055 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10057 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10058 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10059 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10060 | TestCompletionCallback callback; |
| 10061 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10063 | |
| 10064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10066 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10067 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10068 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10070 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10072 | |
| 10073 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10075 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10076 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10077 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10078 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10079 | |
| 10080 | EXPECT_EQ(200, response->headers->response_code()); |
| 10081 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10082 | |
| 10083 | std::string response_data; |
| 10084 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10085 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10086 | EXPECT_EQ("hello!", response_data); |
| 10087 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10088 | LoadTimingInfo load_timing_info; |
| 10089 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10090 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10091 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10092 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10093 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10094 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10095 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10096 | |
| 10097 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10098 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10099 | EXPECT_EQ("pushed", response_data); |
| 10100 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10101 | LoadTimingInfo push_load_timing_info; |
| 10102 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10103 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10104 | // The transactions should share a socket ID, despite being for different |
| 10105 | // origins. |
| 10106 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10107 | push_load_timing_info.socket_log_id); |
| 10108 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10109 | trans.reset(); |
| 10110 | push_trans.reset(); |
| 10111 | session->CloseAllConnections(); |
| 10112 | } |
| 10113 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10114 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10115 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10116 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10117 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10118 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10119 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10120 | HttpRequestInfo request; |
| 10121 | |
| 10122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10123 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10124 | request.traffic_annotation = |
| 10125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10126 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10127 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10128 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10129 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10130 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10131 | |
| 10132 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10133 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10134 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10135 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10137 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10138 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10139 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10140 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10141 | spdy::SpdySerializedFrame push_rst( |
| 10142 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10143 | |
| 10144 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10145 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10146 | }; |
| 10147 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10148 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10149 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10150 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10151 | spdy::SpdySerializedFrame stream1_body( |
| 10152 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10153 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10154 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10155 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10156 | |
| 10157 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10158 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10159 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10160 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10161 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10162 | }; |
| 10163 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10164 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10165 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10166 | // Negotiate SPDY to the proxy |
| 10167 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10168 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10170 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10171 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10172 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10173 | TestCompletionCallback callback; |
| 10174 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10176 | |
| 10177 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10179 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10180 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10181 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10182 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10183 | |
| 10184 | EXPECT_EQ(200, response->headers->response_code()); |
| 10185 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10186 | |
| 10187 | std::string response_data; |
| 10188 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10189 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10190 | EXPECT_EQ("hello!", response_data); |
| 10191 | |
| 10192 | trans.reset(); |
| 10193 | session->CloseAllConnections(); |
| 10194 | } |
| 10195 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10196 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10197 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10198 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10199 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10200 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10201 | proxy_delegate->set_trusted_spdy_proxy( |
| 10202 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10203 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10204 | HttpRequestInfo request; |
| 10205 | |
| 10206 | request.method = "GET"; |
| 10207 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10208 | request.traffic_annotation = |
| 10209 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10210 | |
| 10211 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10212 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10213 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10214 | BoundTestNetLog log; |
| 10215 | session_deps_.net_log = log.bound().net_log(); |
| 10216 | |
| 10217 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10218 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10219 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10220 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10221 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10222 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10223 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10224 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10225 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10226 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10227 | |
| 10228 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10229 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10230 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10231 | }; |
| 10232 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10233 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10234 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10235 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10236 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10237 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10238 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10239 | spdy::SpdySerializedFrame stream1_body( |
| 10240 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10241 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10242 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10243 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10244 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10245 | spdy::SpdySerializedFrame stream2_body( |
| 10246 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10247 | |
| 10248 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10249 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10250 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10251 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10252 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10253 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10254 | }; |
| 10255 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10256 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10257 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10258 | // Negotiate SPDY to the proxy |
| 10259 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10260 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10262 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10263 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10264 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10265 | TestCompletionCallback callback; |
| 10266 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10268 | |
| 10269 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10270 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10272 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10273 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10274 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10275 | |
| 10276 | EXPECT_EQ(200, response->headers->response_code()); |
| 10277 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10278 | |
| 10279 | std::string response_data; |
| 10280 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10281 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10282 | EXPECT_EQ("hello!", response_data); |
| 10283 | |
| 10284 | trans.reset(); |
| 10285 | session->CloseAllConnections(); |
| 10286 | } |
| 10287 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10288 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10289 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10290 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10291 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10292 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10293 | |
| 10294 | HttpRequestInfo request; |
| 10295 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10296 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10297 | request.traffic_annotation = |
| 10298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10299 | |
| 10300 | // Attempt to fetch the URL from a server with a bad cert |
| 10301 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10302 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10303 | "Host: www.example.org:443\r\n" |
| 10304 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10305 | }; |
| 10306 | |
| 10307 | MockRead bad_cert_reads[] = { |
| 10308 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10309 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10310 | }; |
| 10311 | |
| 10312 | // Attempt to fetch the URL with a good cert |
| 10313 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10314 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10315 | "Host: www.example.org:443\r\n" |
| 10316 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10317 | MockWrite("GET / HTTP/1.1\r\n" |
| 10318 | "Host: www.example.org\r\n" |
| 10319 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10320 | }; |
| 10321 | |
| 10322 | MockRead good_cert_reads[] = { |
| 10323 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10324 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10325 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10326 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10327 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10328 | }; |
| 10329 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10330 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10331 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10332 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10333 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10334 | |
| 10335 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10337 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10339 | |
| 10340 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10342 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10345 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10346 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10348 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10349 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10350 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10351 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10352 | |
| 10353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10354 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10356 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10358 | |
| 10359 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10360 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10361 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10362 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10363 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10364 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10365 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10366 | } |
| 10367 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10368 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10369 | HttpRequestInfo request; |
| 10370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10371 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10372 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10373 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10374 | request.traffic_annotation = |
| 10375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10376 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10379 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10380 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10381 | MockWrite( |
| 10382 | "GET / HTTP/1.1\r\n" |
| 10383 | "Host: www.example.org\r\n" |
| 10384 | "Connection: keep-alive\r\n" |
| 10385 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10386 | }; |
| 10387 | |
| 10388 | // Lastly, the server responds with the actual content. |
| 10389 | MockRead data_reads[] = { |
| 10390 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10392 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10394 | }; |
| 10395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10396 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10397 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10399 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10401 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10403 | |
| 10404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10406 | } |
| 10407 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10408 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10409 | // Test user agent values, used both for the request header of the original |
| 10410 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10411 | // no request header / no HttpUserAgentSettings object. |
| 10412 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10413 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10414 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10415 | if (!setting_user_agent) { |
| 10416 | session_deps_.http_user_agent_settings.reset(); |
| 10417 | } else { |
| 10418 | session_deps_.http_user_agent_settings = |
| 10419 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10420 | std::string() /* accept-language */, setting_user_agent); |
| 10421 | } |
| 10422 | session_deps_.proxy_resolution_service = |
| 10423 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10424 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10426 | for (const char* request_user_agent : kTestUserAgents) { |
| 10427 | HttpRequestInfo request; |
| 10428 | request.method = "GET"; |
| 10429 | request.url = GURL("https://www.example.org/"); |
| 10430 | if (request_user_agent) { |
| 10431 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10432 | request_user_agent); |
| 10433 | } |
| 10434 | request.traffic_annotation = |
| 10435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10436 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10438 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10439 | std::string expected_request; |
| 10440 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10441 | expected_request = |
| 10442 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10443 | "Host: www.example.org:443\r\n" |
| 10444 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10445 | } else { |
| 10446 | expected_request = base::StringPrintf( |
| 10447 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10448 | "Host: www.example.org:443\r\n" |
| 10449 | "Proxy-Connection: keep-alive\r\n" |
| 10450 | "User-Agent: %s\r\n\r\n", |
| 10451 | setting_user_agent); |
| 10452 | } |
| 10453 | MockWrite data_writes[] = { |
| 10454 | MockWrite(expected_request.c_str()), |
| 10455 | }; |
| 10456 | MockRead data_reads[] = { |
| 10457 | // Return an error, so the transaction stops here (this test isn't |
| 10458 | // interested in the rest). |
| 10459 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10460 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10461 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10462 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10463 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10464 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10466 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10467 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10468 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10471 | |
| 10472 | rv = callback.WaitForResult(); |
| 10473 | EXPECT_THAT(rv, IsOk()); |
| 10474 | } |
| 10475 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10476 | } |
| 10477 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10478 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10479 | HttpRequestInfo request; |
| 10480 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10481 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10482 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10483 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10484 | request.traffic_annotation = |
| 10485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10486 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10489 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10490 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10491 | MockWrite( |
| 10492 | "GET / HTTP/1.1\r\n" |
| 10493 | "Host: www.example.org\r\n" |
| 10494 | "Connection: keep-alive\r\n" |
| 10495 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10496 | }; |
| 10497 | |
| 10498 | // Lastly, the server responds with the actual content. |
| 10499 | MockRead data_reads[] = { |
| 10500 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10501 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10502 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10503 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10504 | }; |
| 10505 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10506 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10507 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10508 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10509 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10510 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10511 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10512 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10513 | |
| 10514 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10515 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10516 | } |
| 10517 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10518 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10519 | HttpRequestInfo request; |
| 10520 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10521 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10522 | request.traffic_annotation = |
| 10523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10527 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10528 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10529 | MockWrite( |
| 10530 | "POST / HTTP/1.1\r\n" |
| 10531 | "Host: www.example.org\r\n" |
| 10532 | "Connection: keep-alive\r\n" |
| 10533 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10534 | }; |
| 10535 | |
| 10536 | // Lastly, the server responds with the actual content. |
| 10537 | MockRead data_reads[] = { |
| 10538 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10539 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10540 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10542 | }; |
| 10543 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10544 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10547 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10548 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10549 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10551 | |
| 10552 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10553 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10554 | } |
| 10555 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10556 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10557 | HttpRequestInfo request; |
| 10558 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10559 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10560 | request.traffic_annotation = |
| 10561 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10562 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10564 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10565 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10566 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10567 | MockWrite( |
| 10568 | "PUT / HTTP/1.1\r\n" |
| 10569 | "Host: www.example.org\r\n" |
| 10570 | "Connection: keep-alive\r\n" |
| 10571 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10572 | }; |
| 10573 | |
| 10574 | // Lastly, the server responds with the actual content. |
| 10575 | MockRead data_reads[] = { |
| 10576 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10577 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10578 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10579 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10580 | }; |
| 10581 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10582 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10583 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10585 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10586 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10587 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10588 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10589 | |
| 10590 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10591 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10592 | } |
| 10593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10594 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10595 | HttpRequestInfo request; |
| 10596 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10597 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10598 | request.traffic_annotation = |
| 10599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10603 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10604 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10605 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10606 | "Host: www.example.org\r\n" |
| 10607 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10608 | }; |
| 10609 | |
| 10610 | // Lastly, the server responds with the actual content. |
| 10611 | MockRead data_reads[] = { |
| 10612 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10613 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10614 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10615 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10616 | }; |
| 10617 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10618 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10621 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10625 | |
| 10626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10628 | } |
| 10629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10630 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10631 | HttpRequestInfo request; |
| 10632 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10633 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10634 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10635 | request.traffic_annotation = |
| 10636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10640 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10641 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10642 | MockWrite( |
| 10643 | "GET / HTTP/1.1\r\n" |
| 10644 | "Host: www.example.org\r\n" |
| 10645 | "Connection: keep-alive\r\n" |
| 10646 | "Pragma: no-cache\r\n" |
| 10647 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10648 | }; |
| 10649 | |
| 10650 | // Lastly, the server responds with the actual content. |
| 10651 | MockRead data_reads[] = { |
| 10652 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10653 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10654 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10655 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10656 | }; |
| 10657 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10658 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10659 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10661 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10662 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10663 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10665 | |
| 10666 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10667 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10668 | } |
| 10669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10670 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | HttpRequestInfo request; |
| 10672 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10673 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10674 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10675 | request.traffic_annotation = |
| 10676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10677 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10678 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10679 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10680 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10681 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10682 | MockWrite( |
| 10683 | "GET / HTTP/1.1\r\n" |
| 10684 | "Host: www.example.org\r\n" |
| 10685 | "Connection: keep-alive\r\n" |
| 10686 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10687 | }; |
| 10688 | |
| 10689 | // Lastly, the server responds with the actual content. |
| 10690 | MockRead data_reads[] = { |
| 10691 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10692 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10693 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10694 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10695 | }; |
| 10696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10697 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10698 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10700 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10701 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10704 | |
| 10705 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10706 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10707 | } |
| 10708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10709 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10710 | HttpRequestInfo request; |
| 10711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10712 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10713 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10714 | request.traffic_annotation = |
| 10715 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10716 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10719 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10720 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10721 | MockWrite( |
| 10722 | "GET / HTTP/1.1\r\n" |
| 10723 | "Host: www.example.org\r\n" |
| 10724 | "Connection: keep-alive\r\n" |
| 10725 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10726 | }; |
| 10727 | |
| 10728 | // Lastly, the server responds with the actual content. |
| 10729 | MockRead data_reads[] = { |
| 10730 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10731 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10732 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10733 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10734 | }; |
| 10735 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10736 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10739 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10743 | |
| 10744 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10746 | } |
| 10747 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10748 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10749 | HttpRequestInfo request; |
| 10750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10751 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10752 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10753 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10754 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10755 | request.traffic_annotation = |
| 10756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10760 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10761 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10762 | MockWrite( |
| 10763 | "GET / HTTP/1.1\r\n" |
| 10764 | "Host: www.example.org\r\n" |
| 10765 | "Connection: keep-alive\r\n" |
| 10766 | "referer: www.foo.com\r\n" |
| 10767 | "hEllo: Kitty\r\n" |
| 10768 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10769 | }; |
| 10770 | |
| 10771 | // Lastly, the server responds with the actual content. |
| 10772 | MockRead data_reads[] = { |
| 10773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10774 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10775 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10776 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10777 | }; |
| 10778 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10779 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10780 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10781 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10782 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10783 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10784 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10786 | |
| 10787 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10788 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10789 | } |
| 10790 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10791 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10792 | HttpRequestInfo request; |
| 10793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10794 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10795 | request.traffic_annotation = |
| 10796 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10797 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10798 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10799 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10800 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10801 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10802 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10803 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10804 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10805 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10806 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10807 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10808 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10809 | |
| 10810 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10811 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10812 | MockWrite("GET / HTTP/1.1\r\n" |
| 10813 | "Host: www.example.org\r\n" |
| 10814 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10815 | |
| 10816 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10817 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10818 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10819 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10820 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10822 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10823 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10825 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10829 | |
| 10830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10831 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10834 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10835 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10836 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10837 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10838 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10839 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10840 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10841 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10842 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10843 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10845 | EXPECT_EQ("Payload", response_text); |
| 10846 | } |
| 10847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10848 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10849 | HttpRequestInfo request; |
| 10850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10851 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10852 | request.traffic_annotation = |
| 10853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10854 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10855 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10856 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10857 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10858 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10860 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10863 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10864 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10865 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10866 | |
| 10867 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10868 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10869 | base::size(write_buffer)), |
| 10870 | MockWrite("GET / HTTP/1.1\r\n" |
| 10871 | "Host: www.example.org\r\n" |
| 10872 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10873 | |
| 10874 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10875 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10876 | base::size(read_buffer)), |
| 10877 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10879 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10880 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10881 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10883 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10884 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10887 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10888 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10889 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10891 | |
| 10892 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10894 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10895 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10896 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10897 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10898 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10900 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10901 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10902 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10903 | |
| 10904 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10905 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10907 | EXPECT_EQ("Payload", response_text); |
| 10908 | } |
| 10909 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10910 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10911 | HttpRequestInfo request; |
| 10912 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10913 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10914 | request.traffic_annotation = |
| 10915 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10916 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10917 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10918 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10919 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10920 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10921 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10924 | |
| 10925 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10926 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10927 | |
| 10928 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10929 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10930 | MockWrite("GET / HTTP/1.1\r\n" |
| 10931 | "Host: www.example.org\r\n" |
| 10932 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10933 | |
| 10934 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10935 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10936 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10937 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10938 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10942 | |
| 10943 | TestCompletionCallback callback; |
| 10944 | |
tfarina | 4283411 | 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10947 | |
| 10948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10952 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10953 | |
| 10954 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10955 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10956 | TestLoadTimingNotReused(load_timing_info, |
| 10957 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10958 | |
| 10959 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10960 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10962 | EXPECT_EQ("Payload", response_text); |
| 10963 | } |
| 10964 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10965 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10966 | HttpRequestInfo request; |
| 10967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10968 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10969 | request.traffic_annotation = |
| 10970 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10971 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10972 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10973 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10974 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10975 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10976 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10980 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10981 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10982 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10983 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10984 | 0x05, // Version |
| 10985 | 0x01, // Command (CONNECT) |
| 10986 | 0x00, // Reserved. |
| 10987 | 0x03, // Address type (DOMAINNAME). |
| 10988 | 0x0F, // Length of domain (15) |
| 10989 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10990 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10991 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10992 | const char kSOCKS5OkResponse[] = |
| 10993 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10994 | |
| 10995 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10996 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 10997 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 10998 | MockWrite("GET / HTTP/1.1\r\n" |
| 10999 | "Host: www.example.org\r\n" |
| 11000 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11001 | |
| 11002 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11003 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11004 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11005 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11006 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11007 | MockRead("Payload"), |
| 11008 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11009 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11010 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11012 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11013 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11014 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11015 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11017 | |
| 11018 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11021 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11022 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11023 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11024 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11025 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11026 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11027 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11028 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11029 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11030 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11031 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11032 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11033 | EXPECT_EQ("Payload", response_text); |
| 11034 | } |
| 11035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11036 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11037 | HttpRequestInfo request; |
| 11038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11039 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11040 | request.traffic_annotation = |
| 11041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11042 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11043 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11044 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11045 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11046 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11047 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11048 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11051 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11052 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11053 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11054 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11055 | 0x05, // Version |
| 11056 | 0x01, // Command (CONNECT) |
| 11057 | 0x00, // Reserved. |
| 11058 | 0x03, // Address type (DOMAINNAME). |
| 11059 | 0x0F, // Length of domain (15) |
| 11060 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11061 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11062 | }; |
| 11063 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11064 | const char kSOCKS5OkResponse[] = |
| 11065 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11066 | |
| 11067 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11068 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11069 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11070 | base::size(kSOCKS5OkRequest)), |
| 11071 | MockWrite("GET / HTTP/1.1\r\n" |
| 11072 | "Host: www.example.org\r\n" |
| 11073 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11074 | |
| 11075 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11076 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11077 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11078 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11079 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11080 | MockRead("Payload"), |
| 11081 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11082 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11083 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11084 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11085 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11086 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11087 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11089 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11090 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11091 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11093 | |
| 11094 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11097 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11098 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11099 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11100 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11101 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11102 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11103 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11104 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11105 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11106 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11107 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11109 | EXPECT_EQ("Payload", response_text); |
| 11110 | } |
| 11111 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11112 | namespace { |
| 11113 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11114 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11115 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11116 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11117 | std::string proxy_server; |
| 11118 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11119 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11120 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11121 | }; |
| 11122 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11123 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11124 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11126 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11127 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11128 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11129 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11130 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11131 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11132 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11133 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11134 | |
| 11135 | return session; |
| 11136 | } |
| 11137 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11138 | int GroupIdTransactionHelper(const std::string& url, |
| 11139 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11140 | HttpRequestInfo request; |
| 11141 | request.method = "GET"; |
| 11142 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11143 | request.traffic_annotation = |
| 11144 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11148 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11149 | |
| 11150 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11151 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11152 | } |
| 11153 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11154 | } // namespace |
| 11155 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11156 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11157 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11158 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11159 | "", // unused |
| 11160 | "http://www.example.org/direct", |
| 11161 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11162 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11163 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11164 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11165 | }, |
| 11166 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11167 | "", // unused |
| 11168 | "http://[2001:1418:13:1::25]/direct", |
| 11169 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11170 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11171 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11172 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11173 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11174 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11175 | // SSL Tests |
| 11176 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11177 | "", // unused |
| 11178 | "https://www.example.org/direct_ssl", |
| 11179 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11180 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11181 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11182 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11183 | }, |
| 11184 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11185 | "", // unused |
| 11186 | "https://[2001:1418:13:1::25]/direct", |
| 11187 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11188 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11189 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11190 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11191 | }, |
| 11192 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11193 | "", // unused |
| 11194 | "https://host.with.alternate/direct", |
| 11195 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11196 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11197 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11198 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11199 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11200 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11201 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11202 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11203 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11204 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11205 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11206 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11207 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11208 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11209 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11210 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11211 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11212 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11213 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11214 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11215 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11216 | |
| 11217 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11218 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11219 | EXPECT_EQ(tests[i].expected_group_id, |
| 11220 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11221 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11222 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11223 | } |
| 11224 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11225 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11226 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11227 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11228 | "http_proxy", |
| 11229 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11230 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11231 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11232 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11233 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11234 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11235 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11236 | // SSL Tests |
| 11237 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11238 | "http_proxy", |
| 11239 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11240 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11241 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11242 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11243 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11244 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11245 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11246 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11247 | "http_proxy", |
| 11248 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11249 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11250 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11251 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11252 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11253 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11254 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11255 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11256 | "http_proxy", |
| 11257 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11258 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11259 | ClientSocketPool::SocketType::kFtp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11260 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11261 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11262 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11263 | }; |
| 11264 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11265 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11266 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11267 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11268 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11269 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11270 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11271 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11272 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11273 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11274 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11275 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11276 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11277 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11278 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11279 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11280 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11281 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11282 | |
| 11283 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11284 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11285 | EXPECT_EQ(tests[i].expected_group_id, |
| 11286 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11287 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11288 | } |
| 11289 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11290 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11291 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11292 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11293 | "socks4://socks_proxy:1080", |
| 11294 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11295 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11296 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11297 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11298 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11299 | }, |
| 11300 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11301 | "socks5://socks_proxy:1080", |
| 11302 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11303 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11304 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11305 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11306 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11307 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11308 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11309 | // SSL Tests |
| 11310 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11311 | "socks4://socks_proxy:1080", |
| 11312 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11313 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11314 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11315 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11316 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11317 | }, |
| 11318 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11319 | "socks5://socks_proxy:1080", |
| 11320 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11321 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11322 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11323 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11324 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11325 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11326 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11327 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11328 | "socks4://socks_proxy:1080", |
| 11329 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11330 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11331 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11332 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11333 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11334 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11335 | }; |
| 11336 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11337 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11338 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11339 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11340 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11341 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11342 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11343 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11344 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11345 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11346 | ProxyServer proxy_server( |
| 11347 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11348 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11349 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11350 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11351 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11352 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11353 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11354 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11357 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11358 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11359 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11360 | EXPECT_EQ(tests[i].expected_group_id, |
| 11361 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11362 | } |
| 11363 | } |
| 11364 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11365 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11366 | HttpRequestInfo request; |
| 11367 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11368 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11369 | request.traffic_annotation = |
| 11370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11371 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11372 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11373 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11374 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11375 | // This simulates failure resolving all hostnames; that means we will fail |
| 11376 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11377 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11378 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11380 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11381 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11382 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11386 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11388 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11389 | } |
| 11390 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11391 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11392 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11393 | HttpRequestInfo request; |
| 11394 | request.method = "GET"; |
| 11395 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11396 | request.traffic_annotation = |
| 11397 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11398 | |
| 11399 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11400 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11401 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11402 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11404 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11405 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11406 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11410 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11412 | |
| 11413 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11414 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11415 | |
| 11416 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11417 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11418 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11419 | } |
| 11420 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11421 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11422 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11423 | HttpRequestInfo request; |
| 11424 | request.method = "GET"; |
| 11425 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11426 | request.traffic_annotation = |
| 11427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11428 | |
| 11429 | MockRead data_reads[] = { |
| 11430 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11432 | }; |
| 11433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11434 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11438 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11444 | |
| 11445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11446 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11448 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11449 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11450 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11451 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11452 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11453 | |
| 11454 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11455 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11456 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11457 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11458 | |
| 11459 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11460 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11461 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11462 | } |
| 11463 | |
| 11464 | // Make sure that a dropped connection while draining the body for auth |
| 11465 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11466 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11467 | HttpRequestInfo request; |
| 11468 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11469 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11470 | request.traffic_annotation = |
| 11471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11472 | |
| 11473 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11474 | MockWrite( |
| 11475 | "GET / HTTP/1.1\r\n" |
| 11476 | "Host: www.example.org\r\n" |
| 11477 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11478 | }; |
| 11479 | |
| 11480 | MockRead data_reads1[] = { |
| 11481 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11482 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11483 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11484 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11485 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11486 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11487 | }; |
| 11488 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11489 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11490 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11492 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11493 | // be issuing -- the final header line contains the credentials. |
| 11494 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11495 | MockWrite( |
| 11496 | "GET / HTTP/1.1\r\n" |
| 11497 | "Host: www.example.org\r\n" |
| 11498 | "Connection: keep-alive\r\n" |
| 11499 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11500 | }; |
| 11501 | |
| 11502 | // Lastly, the server responds with the actual content. |
| 11503 | MockRead data_reads2[] = { |
| 11504 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11505 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11506 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11508 | }; |
| 11509 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11510 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11511 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11514 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11517 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11518 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11520 | |
| 11521 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11524 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11525 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11526 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11528 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11530 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11532 | |
| 11533 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11534 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11536 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11537 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11538 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11539 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11540 | } |
| 11541 | |
| 11542 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11543 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11544 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11545 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11546 | |
| 11547 | HttpRequestInfo request; |
| 11548 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11549 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11550 | request.traffic_annotation = |
| 11551 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11552 | |
| 11553 | MockRead proxy_reads[] = { |
| 11554 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11555 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11556 | }; |
| 11557 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11558 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11559 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11560 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11561 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11564 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11565 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11566 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11570 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11571 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11573 | |
| 11574 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11575 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11576 | } |
| 11577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11578 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11579 | HttpRequestInfo request; |
| 11580 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11581 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11582 | request.traffic_annotation = |
| 11583 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11584 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11586 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11587 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11588 | MockRead data_reads[] = { |
| 11589 | 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] | 11590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11591 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11592 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11593 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11596 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11600 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11601 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11604 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11605 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11606 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11607 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11608 | |
| 11609 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11610 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11611 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11612 | } |
| 11613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11614 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11615 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11616 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11617 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11618 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11619 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11620 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11621 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11622 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11623 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11624 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11625 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11626 | |
| 11627 | HttpRequestInfo request; |
| 11628 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11629 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11630 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11631 | request.traffic_annotation = |
| 11632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11636 | |
| 11637 | MockRead data_reads[] = { |
| 11638 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11639 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11640 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11641 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11642 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11643 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11644 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11645 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11646 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11647 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11649 | |
| 11650 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11651 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11653 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11654 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11655 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11656 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11657 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11658 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11659 | } |
| 11660 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11661 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11662 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11663 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11664 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11665 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11666 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11667 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11668 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11670 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11671 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11672 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11673 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11674 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11675 | |
| 11676 | HttpRequestInfo request; |
| 11677 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11678 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11679 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11680 | request.traffic_annotation = |
| 11681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11682 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11683 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11686 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11687 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11690 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11691 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11692 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11694 | |
| 11695 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11696 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11697 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11698 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11699 | } |
| 11700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11701 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11702 | class FakeUploadElementReader : public UploadElementReader { |
| 11703 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11704 | FakeUploadElementReader() = default; |
| 11705 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11706 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11707 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11708 | |
| 11709 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11710 | int Init(CompletionOnceCallback callback) override { |
| 11711 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11712 | return ERR_IO_PENDING; |
| 11713 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11714 | uint64_t GetContentLength() const override { return 0; } |
| 11715 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11716 | int Read(IOBuffer* buf, |
| 11717 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11718 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11719 | return ERR_FAILED; |
| 11720 | } |
| 11721 | |
| 11722 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11723 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11724 | }; |
| 11725 | |
| 11726 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11727 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11728 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11729 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11730 | |
| 11731 | HttpRequestInfo request; |
| 11732 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11733 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11734 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11735 | request.traffic_annotation = |
| 11736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11739 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11740 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11741 | |
| 11742 | StaticSocketDataProvider data; |
| 11743 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11744 | |
| 11745 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11746 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11748 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11749 | |
| 11750 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11751 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11752 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11753 | |
| 11754 | // Return Init()'s result after the transaction gets destroyed. |
| 11755 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11756 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11757 | } |
| 11758 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11759 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11760 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11761 | HttpRequestInfo request; |
| 11762 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11763 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11764 | request.traffic_annotation = |
| 11765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11766 | |
| 11767 | // First transaction will request a resource and receive a Basic challenge |
| 11768 | // with realm="first_realm". |
| 11769 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11770 | MockWrite( |
| 11771 | "GET / HTTP/1.1\r\n" |
| 11772 | "Host: www.example.org\r\n" |
| 11773 | "Connection: keep-alive\r\n" |
| 11774 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11775 | }; |
| 11776 | MockRead data_reads1[] = { |
| 11777 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11778 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11779 | "\r\n"), |
| 11780 | }; |
| 11781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11782 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11783 | // for first_realm. The server will reject and provide a challenge with |
| 11784 | // second_realm. |
| 11785 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11786 | MockWrite( |
| 11787 | "GET / HTTP/1.1\r\n" |
| 11788 | "Host: www.example.org\r\n" |
| 11789 | "Connection: keep-alive\r\n" |
| 11790 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11791 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11792 | }; |
| 11793 | MockRead data_reads2[] = { |
| 11794 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11795 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11796 | "\r\n"), |
| 11797 | }; |
| 11798 | |
| 11799 | // This again fails, and goes back to first_realm. Make sure that the |
| 11800 | // entry is removed from cache. |
| 11801 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11802 | MockWrite( |
| 11803 | "GET / HTTP/1.1\r\n" |
| 11804 | "Host: www.example.org\r\n" |
| 11805 | "Connection: keep-alive\r\n" |
| 11806 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11807 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11808 | }; |
| 11809 | MockRead data_reads3[] = { |
| 11810 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11811 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11812 | "\r\n"), |
| 11813 | }; |
| 11814 | |
| 11815 | // Try one last time (with the correct password) and get the resource. |
| 11816 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11817 | MockWrite( |
| 11818 | "GET / HTTP/1.1\r\n" |
| 11819 | "Host: www.example.org\r\n" |
| 11820 | "Connection: keep-alive\r\n" |
| 11821 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11822 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11823 | }; |
| 11824 | MockRead data_reads4[] = { |
| 11825 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11826 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11827 | "Content-Length: 5\r\n" |
| 11828 | "\r\n" |
| 11829 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11830 | }; |
| 11831 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11832 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11833 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11834 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11835 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11836 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11837 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11838 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11839 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11841 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11842 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11844 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11845 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11846 | // Issue the first request with Authorize headers. There should be a |
| 11847 | // password prompt for first_realm waiting to be filled in after the |
| 11848 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11849 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11851 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11852 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11853 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11854 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11855 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11856 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11857 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11858 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11859 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11860 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11861 | |
| 11862 | // Issue the second request with an incorrect password. There should be a |
| 11863 | // password prompt for second_realm waiting to be filled in after the |
| 11864 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11865 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11866 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11867 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11868 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11869 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11870 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11871 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11872 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11873 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11874 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11875 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11876 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11877 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11878 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11879 | |
| 11880 | // Issue the third request with another incorrect password. There should be |
| 11881 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11882 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11883 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11884 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11885 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11886 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11888 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11889 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11890 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11891 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11892 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11893 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11894 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11895 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11896 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11897 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11898 | |
| 11899 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11900 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11901 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11902 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11904 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11905 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11906 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11907 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11908 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11909 | } |
| 11910 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11911 | // Regression test for https://crbug.com/754395. |
| 11912 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11913 | MockRead data_reads[] = { |
| 11914 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11915 | MockRead(kAlternativeServiceHttpHeader), |
| 11916 | MockRead("\r\n"), |
| 11917 | MockRead("hello world"), |
| 11918 | MockRead(SYNCHRONOUS, OK), |
| 11919 | }; |
| 11920 | |
| 11921 | HttpRequestInfo request; |
| 11922 | request.method = "GET"; |
| 11923 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11924 | request.traffic_annotation = |
| 11925 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11926 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11927 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11929 | |
| 11930 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11931 | ssl.ssl_info.cert = |
| 11932 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11933 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11934 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11936 | |
| 11937 | TestCompletionCallback callback; |
| 11938 | |
| 11939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11941 | |
| 11942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11944 | |
| 11945 | url::SchemeHostPort test_server(request.url); |
| 11946 | HttpServerProperties* http_server_properties = |
| 11947 | session->http_server_properties(); |
| 11948 | EXPECT_TRUE( |
| 11949 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11950 | |
| 11951 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11952 | |
| 11953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11954 | ASSERT_TRUE(response); |
| 11955 | ASSERT_TRUE(response->headers); |
| 11956 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11957 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11958 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11959 | |
| 11960 | std::string response_data; |
| 11961 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11962 | EXPECT_EQ("hello world", response_data); |
| 11963 | |
| 11964 | EXPECT_TRUE( |
| 11965 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11966 | } |
| 11967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11968 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11969 | MockRead data_reads[] = { |
| 11970 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11971 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11972 | MockRead("\r\n"), |
| 11973 | MockRead("hello world"), |
| 11974 | MockRead(SYNCHRONOUS, OK), |
| 11975 | }; |
| 11976 | |
| 11977 | HttpRequestInfo request; |
| 11978 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11979 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11980 | request.traffic_annotation = |
| 11981 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11982 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11983 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11984 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11985 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11986 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11987 | ssl.ssl_info.cert = |
| 11988 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11989 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11991 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11992 | TestCompletionCallback callback; |
| 11993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11995 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11997 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11999 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12000 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12001 | HttpServerProperties* http_server_properties = |
| 12002 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12003 | EXPECT_TRUE( |
| 12004 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12005 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12006 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12008 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12009 | ASSERT_TRUE(response); |
| 12010 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12011 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12012 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12013 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12014 | |
| 12015 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12016 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12017 | EXPECT_EQ("hello world", response_data); |
| 12018 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12019 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12020 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12021 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12022 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12023 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12024 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12025 | } |
| 12026 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12027 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12028 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12029 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12030 | MockRead data_reads[] = { |
| 12031 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12032 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12033 | MockRead("\r\n"), |
| 12034 | MockRead("hello world"), |
| 12035 | MockRead(SYNCHRONOUS, OK), |
| 12036 | }; |
| 12037 | |
| 12038 | HttpRequestInfo request; |
| 12039 | request.method = "GET"; |
| 12040 | request.url = GURL("http://www.example.org/"); |
| 12041 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12042 | request.traffic_annotation = |
| 12043 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12044 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12045 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12046 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12047 | |
| 12048 | TestCompletionCallback callback; |
| 12049 | |
| 12050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12052 | |
| 12053 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12054 | HttpServerProperties* http_server_properties = |
| 12055 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12056 | EXPECT_TRUE( |
| 12057 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12059 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12061 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12063 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12064 | ASSERT_TRUE(response); |
| 12065 | ASSERT_TRUE(response->headers); |
| 12066 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12067 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12068 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12069 | |
| 12070 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12071 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12072 | EXPECT_EQ("hello world", response_data); |
| 12073 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12074 | EXPECT_TRUE( |
| 12075 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12076 | } |
| 12077 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12078 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12079 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12080 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12081 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12082 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12083 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12084 | HttpRequestInfo request; |
| 12085 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12086 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12087 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12088 | request.traffic_annotation = |
| 12089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12090 | |
| 12091 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12092 | StaticSocketDataProvider first_data; |
| 12093 | first_data.set_connect_data(mock_connect); |
| 12094 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12095 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12096 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12098 | |
| 12099 | MockRead data_reads[] = { |
| 12100 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12101 | MockRead(ASYNC, OK), |
| 12102 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12103 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12104 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12105 | |
| 12106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12107 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12108 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12109 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12110 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12111 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12112 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12113 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12114 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12117 | TestCompletionCallback callback; |
| 12118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12120 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12121 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12122 | } |
| 12123 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12124 | // Regression test for https://crbug.com/615497: |
| 12125 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12126 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12127 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12128 | HttpRequestInfo request; |
| 12129 | request.method = "GET"; |
| 12130 | request.url = GURL("http://www.example.org/"); |
| 12131 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12132 | request.traffic_annotation = |
| 12133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12134 | |
| 12135 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12136 | StaticSocketDataProvider first_data; |
| 12137 | first_data.set_connect_data(mock_connect); |
| 12138 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12139 | |
| 12140 | MockRead data_reads[] = { |
| 12141 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12142 | MockRead(ASYNC, OK), |
| 12143 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12144 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12145 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12146 | |
| 12147 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12148 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12149 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12150 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12151 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12152 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12153 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12154 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12155 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12157 | TestCompletionCallback callback; |
| 12158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12159 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12160 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12161 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12162 | } |
| 12163 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12164 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12165 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12166 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12167 | HttpServerProperties* http_server_properties = |
| 12168 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12169 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12170 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12171 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12172 | http_server_properties->SetQuicAlternativeService( |
| 12173 | test_server, alternative_service, expiration, |
| 12174 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12175 | EXPECT_EQ( |
| 12176 | 1u, |
| 12177 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12178 | |
| 12179 | // Send a clear header. |
| 12180 | MockRead data_reads[] = { |
| 12181 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12182 | MockRead("Alt-Svc: clear\r\n"), |
| 12183 | MockRead("\r\n"), |
| 12184 | MockRead("hello world"), |
| 12185 | MockRead(SYNCHRONOUS, OK), |
| 12186 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12187 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12189 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12190 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12191 | ssl.ssl_info.cert = |
| 12192 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12193 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12194 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12195 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12196 | HttpRequestInfo request; |
| 12197 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12198 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12199 | request.traffic_annotation = |
| 12200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12201 | |
| 12202 | TestCompletionCallback callback; |
| 12203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12204 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12205 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12206 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12207 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12209 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12210 | ASSERT_TRUE(response); |
| 12211 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12212 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12213 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12214 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12215 | |
| 12216 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12217 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12218 | EXPECT_EQ("hello world", response_data); |
| 12219 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12220 | EXPECT_TRUE( |
| 12221 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12222 | } |
| 12223 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12224 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12225 | MockRead data_reads[] = { |
| 12226 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12227 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12228 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12229 | MockRead("hello world"), |
| 12230 | MockRead(SYNCHRONOUS, OK), |
| 12231 | }; |
| 12232 | |
| 12233 | HttpRequestInfo request; |
| 12234 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12235 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12236 | request.traffic_annotation = |
| 12237 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12238 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12239 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12240 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12241 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12242 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12243 | ssl.ssl_info.cert = |
| 12244 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12245 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12247 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12248 | TestCompletionCallback callback; |
| 12249 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12253 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12255 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12256 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12257 | HttpServerProperties* http_server_properties = |
| 12258 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12259 | EXPECT_TRUE( |
| 12260 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12261 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12262 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12264 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12265 | ASSERT_TRUE(response); |
| 12266 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12267 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12268 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12269 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12270 | |
| 12271 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12272 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12273 | EXPECT_EQ("hello world", response_data); |
| 12274 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12275 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12276 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12277 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12278 | |
| 12279 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12280 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12281 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12282 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12283 | 1234); |
| 12284 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12285 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12286 | } |
| 12287 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12288 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12289 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12290 | HostPortPair alternative("alternative.example.org", 443); |
| 12291 | std::string origin_url = "https://origin.example.org:443"; |
| 12292 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12293 | |
| 12294 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12295 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12296 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12298 | |
| 12299 | // HTTP/1.1 data for request. |
| 12300 | MockWrite http_writes[] = { |
| 12301 | MockWrite("GET / HTTP/1.1\r\n" |
| 12302 | "Host: alternative.example.org\r\n" |
| 12303 | "Connection: keep-alive\r\n\r\n"), |
| 12304 | }; |
| 12305 | |
| 12306 | MockRead http_reads[] = { |
| 12307 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12308 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12309 | "Content-Length: 40\r\n\r\n" |
| 12310 | "first HTTP/1.1 response from alternative"), |
| 12311 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12312 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12313 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12314 | |
| 12315 | StaticSocketDataProvider data_refused; |
| 12316 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12317 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12318 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12319 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12320 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12321 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12322 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12323 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12324 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12325 | http_server_properties->SetQuicAlternativeService( |
| 12326 | server, alternative_service, expiration, |
| 12327 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12328 | // Mark the QUIC alternative service as broken. |
| 12329 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12330 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12331 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12332 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12333 | request.method = "GET"; |
| 12334 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12335 | request.traffic_annotation = |
| 12336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12337 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12338 | TestCompletionCallback callback; |
| 12339 | NetErrorDetails details; |
| 12340 | EXPECT_FALSE(details.quic_broken); |
| 12341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12342 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12343 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12344 | EXPECT_TRUE(details.quic_broken); |
| 12345 | } |
| 12346 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12347 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12348 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12349 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12350 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12351 | std::string origin_url = "https://origin.example.org:443"; |
| 12352 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12353 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12354 | |
| 12355 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12356 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12357 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12359 | |
| 12360 | // HTTP/1.1 data for request. |
| 12361 | MockWrite http_writes[] = { |
| 12362 | MockWrite("GET / HTTP/1.1\r\n" |
| 12363 | "Host: alternative1.example.org\r\n" |
| 12364 | "Connection: keep-alive\r\n\r\n"), |
| 12365 | }; |
| 12366 | |
| 12367 | MockRead http_reads[] = { |
| 12368 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12369 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12370 | "Content-Length: 40\r\n\r\n" |
| 12371 | "first HTTP/1.1 response from alternative1"), |
| 12372 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12373 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12374 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12375 | |
| 12376 | StaticSocketDataProvider data_refused; |
| 12377 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12378 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12379 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12380 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12381 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12382 | session->http_server_properties(); |
| 12383 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12384 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12385 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12386 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12387 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12388 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12389 | alternative_service_info_vector.push_back( |
| 12390 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12391 | alternative_service1, expiration, |
| 12392 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12393 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12394 | alternative_service_info_vector.push_back( |
| 12395 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12396 | alternative_service2, expiration, |
| 12397 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12398 | |
| 12399 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12400 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12401 | |
| 12402 | // Mark one of the QUIC alternative service as broken. |
| 12403 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12404 | EXPECT_EQ(2u, |
| 12405 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12406 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12407 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12409 | request.method = "GET"; |
| 12410 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12411 | request.traffic_annotation = |
| 12412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12413 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12414 | TestCompletionCallback callback; |
| 12415 | NetErrorDetails details; |
| 12416 | EXPECT_FALSE(details.quic_broken); |
| 12417 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12418 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12419 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12420 | EXPECT_FALSE(details.quic_broken); |
| 12421 | } |
| 12422 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12423 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12424 | HttpRequestInfo request; |
| 12425 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12426 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12427 | request.traffic_annotation = |
| 12428 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12429 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12430 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12431 | StaticSocketDataProvider first_data; |
| 12432 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12433 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12434 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12435 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12437 | |
| 12438 | MockRead data_reads[] = { |
| 12439 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12440 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12441 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12442 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12443 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12444 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12447 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12448 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12449 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12450 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12451 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12452 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12453 | // Port is ignored by MockConnect anyway. |
| 12454 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12455 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12456 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12457 | http_server_properties->SetHttp2AlternativeService( |
| 12458 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12461 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12463 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12465 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12467 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12468 | ASSERT_TRUE(response); |
| 12469 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12470 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12471 | |
| 12472 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12473 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12474 | EXPECT_EQ("hello world", response_data); |
| 12475 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12476 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12477 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12478 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12479 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12480 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12481 | EXPECT_TRUE( |
| 12482 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12483 | } |
| 12484 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12485 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12486 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12487 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12488 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12489 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12490 | HttpRequestInfo restricted_port_request; |
| 12491 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12492 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12493 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12494 | restricted_port_request.traffic_annotation = |
| 12495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12496 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12497 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12498 | StaticSocketDataProvider first_data; |
| 12499 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12500 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12501 | |
| 12502 | MockRead data_reads[] = { |
| 12503 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12504 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12505 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12506 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12507 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12508 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12509 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12510 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12514 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12515 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12516 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12517 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12518 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12519 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12520 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12521 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12522 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12523 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12524 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12525 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12526 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12527 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12528 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12529 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12531 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12532 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12533 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12534 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12535 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12536 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12537 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12538 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12539 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12540 | |
| 12541 | HttpRequestInfo restricted_port_request; |
| 12542 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12543 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12544 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12545 | restricted_port_request.traffic_annotation = |
| 12546 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12547 | |
| 12548 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12549 | StaticSocketDataProvider first_data; |
| 12550 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12551 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12552 | |
| 12553 | MockRead data_reads[] = { |
| 12554 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12555 | MockRead("hello world"), |
| 12556 | MockRead(ASYNC, OK), |
| 12557 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12558 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12559 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12560 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12561 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12565 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12566 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12567 | session->http_server_properties(); |
| 12568 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12569 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12570 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12571 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12572 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12573 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12574 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12577 | TestCompletionCallback callback; |
| 12578 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12579 | EXPECT_EQ(ERR_IO_PENDING, |
| 12580 | trans.Start(&restricted_port_request, callback.callback(), |
| 12581 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12582 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12583 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12584 | } |
| 12585 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12586 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12587 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12588 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12589 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12590 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12591 | HttpRequestInfo restricted_port_request; |
| 12592 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12593 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12594 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12595 | restricted_port_request.traffic_annotation = |
| 12596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12597 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12598 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12599 | StaticSocketDataProvider first_data; |
| 12600 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12601 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12602 | |
| 12603 | MockRead data_reads[] = { |
| 12604 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12605 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12606 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12607 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12608 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12609 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12610 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12611 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12615 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12616 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12617 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12618 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12619 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12620 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12621 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12622 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12623 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12624 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12627 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12629 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12630 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12632 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12633 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12634 | } |
| 12635 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12636 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12637 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12638 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12639 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12640 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12641 | HttpRequestInfo unrestricted_port_request; |
| 12642 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12643 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12644 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12645 | unrestricted_port_request.traffic_annotation = |
| 12646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12647 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12648 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12649 | StaticSocketDataProvider first_data; |
| 12650 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12651 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12652 | |
| 12653 | MockRead data_reads[] = { |
| 12654 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12655 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12656 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12657 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12658 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12659 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12660 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12661 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12663 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12665 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12666 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12667 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12668 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12669 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12670 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12671 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12672 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12673 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12674 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12677 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12679 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12680 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12682 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12683 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12684 | } |
| 12685 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12686 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12687 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12688 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12689 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12690 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12691 | HttpRequestInfo unrestricted_port_request; |
| 12692 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12693 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12694 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12695 | unrestricted_port_request.traffic_annotation = |
| 12696 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12697 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12698 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12699 | StaticSocketDataProvider first_data; |
| 12700 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12701 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12702 | |
| 12703 | MockRead data_reads[] = { |
| 12704 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12705 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12706 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12707 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12708 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12709 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12710 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12711 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12713 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12715 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12716 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12717 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12718 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12719 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12720 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12721 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12722 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12723 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12724 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12727 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12729 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12730 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12732 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12733 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12734 | } |
| 12735 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12736 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12737 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12738 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12739 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12740 | HttpRequestInfo request; |
| 12741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12742 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12743 | request.traffic_annotation = |
| 12744 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12745 | |
| 12746 | // The alternate protocol request will error out before we attempt to connect, |
| 12747 | // so only the standard HTTP request will try to connect. |
| 12748 | MockRead data_reads[] = { |
| 12749 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12750 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12751 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12752 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12753 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12755 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12757 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12758 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12759 | session->http_server_properties(); |
| 12760 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12761 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12762 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12763 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12764 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12765 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12768 | TestCompletionCallback callback; |
| 12769 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12770 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12772 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12773 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12774 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12775 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12776 | ASSERT_TRUE(response); |
| 12777 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12778 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12779 | |
| 12780 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12781 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12782 | EXPECT_EQ("hello world", response_data); |
| 12783 | } |
| 12784 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12785 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12786 | HttpRequestInfo request; |
| 12787 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12788 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12789 | request.traffic_annotation = |
| 12790 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12791 | |
| 12792 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12793 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12794 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12795 | MockRead("\r\n"), |
| 12796 | MockRead("hello world"), |
| 12797 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12798 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12800 | StaticSocketDataProvider first_transaction(data_reads, |
| 12801 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12802 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12803 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12804 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12806 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12807 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12808 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12809 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12810 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12811 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12812 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12813 | spdy::SpdySerializedFrame resp( |
| 12814 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12815 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12816 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12817 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12818 | }; |
| 12819 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12820 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12821 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12822 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12823 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12824 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12825 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12826 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12827 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12828 | &hanging_non_alternate_protocol_socket); |
| 12829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12830 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12833 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12834 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12836 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12838 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12839 | |
| 12840 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12841 | ASSERT_TRUE(response); |
| 12842 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12843 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12844 | |
| 12845 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12846 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12847 | EXPECT_EQ("hello world", response_data); |
| 12848 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12849 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12852 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12854 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12855 | |
| 12856 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12857 | ASSERT_TRUE(response); |
| 12858 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12859 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12860 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12861 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12862 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12863 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12864 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12865 | } |
| 12866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12867 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12868 | HttpRequestInfo request; |
| 12869 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12870 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12871 | request.traffic_annotation = |
| 12872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12873 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12874 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12875 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12876 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12877 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12878 | MockRead("\r\n"), |
| 12879 | MockRead("hello world"), |
| 12880 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12881 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12882 | }; |
| 12883 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12884 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12885 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12886 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12887 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12888 | ssl_http11.ssl_info.cert = |
| 12889 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12890 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12892 | |
| 12893 | // Second transaction starts an alternative and a non-alternative Job. |
| 12894 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12895 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12896 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12897 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12898 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12899 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12900 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12901 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12902 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12903 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12904 | // Third transaction starts an alternative and a non-alternative job. |
| 12905 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12906 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12907 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12908 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12909 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12910 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12911 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12912 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12913 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12914 | spdy::SpdySerializedFrame resp1( |
| 12915 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12916 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12917 | spdy::SpdySerializedFrame resp2( |
| 12918 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12919 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12920 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12921 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12922 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12923 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12924 | }; |
| 12925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12926 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12927 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12928 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12929 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12930 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12931 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12932 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12933 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12934 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12936 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12937 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12939 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12941 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12942 | |
| 12943 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12944 | ASSERT_TRUE(response); |
| 12945 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12946 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12947 | |
| 12948 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12949 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12950 | EXPECT_EQ("hello world", response_data); |
| 12951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12952 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12953 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12954 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12957 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12958 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12959 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12961 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12962 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12963 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12964 | |
| 12965 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12966 | ASSERT_TRUE(response); |
| 12967 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12968 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12969 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12970 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12971 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12972 | EXPECT_EQ("hello!", response_data); |
| 12973 | |
| 12974 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12975 | ASSERT_TRUE(response); |
| 12976 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12977 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12978 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12979 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12980 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12981 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12982 | } |
| 12983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12984 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12985 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12986 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12987 | HttpRequestInfo request; |
| 12988 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12989 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12990 | request.traffic_annotation = |
| 12991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12992 | |
| 12993 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12994 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12995 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12996 | MockRead("\r\n"), |
| 12997 | MockRead("hello world"), |
| 12998 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12999 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13000 | }; |
| 13001 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13002 | StaticSocketDataProvider first_transaction(data_reads, |
| 13003 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13004 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13005 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13006 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13007 | ssl.ssl_info.cert = |
| 13008 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13009 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13011 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13012 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13013 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13014 | hanging_alternate_protocol_socket.set_connect_data( |
| 13015 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13016 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13017 | &hanging_alternate_protocol_socket); |
| 13018 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13019 | // 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] | 13020 | StaticSocketDataProvider second_transaction(data_reads, |
| 13021 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13022 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13023 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13024 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13025 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13028 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13029 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13030 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13031 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13033 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13034 | |
| 13035 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13036 | ASSERT_TRUE(response); |
| 13037 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13038 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13039 | |
| 13040 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13041 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13042 | EXPECT_EQ("hello world", response_data); |
| 13043 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13044 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13045 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13046 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13047 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13049 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13050 | |
| 13051 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13052 | ASSERT_TRUE(response); |
| 13053 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13054 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13055 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13056 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13057 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13058 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13059 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13060 | } |
| 13061 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13062 | // Test that proxy is resolved using the origin url, |
| 13063 | // regardless of the alternative server. |
| 13064 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13065 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13066 | ProxyConfig proxy_config; |
| 13067 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13068 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13069 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13070 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13071 | |
| 13072 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13073 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13074 | &capturing_proxy_resolver); |
| 13075 | |
| 13076 | TestNetLog net_log; |
| 13077 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13078 | session_deps_.proxy_resolution_service = |
| 13079 | std::make_unique<ProxyResolutionService>( |
| 13080 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13081 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13082 | |
| 13083 | session_deps_.net_log = &net_log; |
| 13084 | |
| 13085 | // Configure alternative service with a hostname that is not bypassed by the |
| 13086 | // proxy. |
| 13087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13088 | HttpServerProperties* http_server_properties = |
| 13089 | session->http_server_properties(); |
| 13090 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13091 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13092 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13093 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13094 | http_server_properties->SetHttp2AlternativeService( |
| 13095 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13096 | |
| 13097 | // Non-alternative job should hang. |
| 13098 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13099 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13100 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13101 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13102 | &hanging_alternate_protocol_socket); |
| 13103 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13104 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13105 | |
| 13106 | HttpRequestInfo request; |
| 13107 | request.method = "GET"; |
| 13108 | request.url = GURL("https://www.example.org/"); |
| 13109 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13110 | request.traffic_annotation = |
| 13111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13112 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13113 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13114 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13115 | |
| 13116 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13117 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13118 | spdy::SpdySerializedFrame resp( |
| 13119 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13120 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13121 | MockRead spdy_reads[] = { |
| 13122 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13123 | }; |
| 13124 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13125 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13126 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13127 | |
| 13128 | TestCompletionCallback callback; |
| 13129 | |
| 13130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13131 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13132 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13133 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13134 | |
| 13135 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13136 | ASSERT_TRUE(response); |
| 13137 | ASSERT_TRUE(response->headers); |
| 13138 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13139 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13140 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13141 | |
| 13142 | std::string response_data; |
| 13143 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13144 | EXPECT_EQ("hello!", response_data); |
| 13145 | |
| 13146 | // Origin host bypasses proxy, no resolution should have happened. |
| 13147 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13148 | } |
| 13149 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13150 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13151 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13152 | proxy_config.set_auto_detect(true); |
| 13153 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13154 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13155 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13156 | session_deps_.proxy_resolution_service = |
| 13157 | std::make_unique<ProxyResolutionService>( |
| 13158 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13159 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13160 | std::make_unique<CapturingProxyResolverFactory>( |
| 13161 | &capturing_proxy_resolver), |
| 13162 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13163 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13164 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13165 | |
| 13166 | HttpRequestInfo request; |
| 13167 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13168 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13169 | request.traffic_annotation = |
| 13170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13171 | |
| 13172 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13173 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13174 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13175 | MockRead("\r\n"), |
| 13176 | MockRead("hello world"), |
| 13177 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13178 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13179 | }; |
| 13180 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13181 | StaticSocketDataProvider first_transaction(data_reads, |
| 13182 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13183 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13184 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13185 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13187 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13188 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13189 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13190 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13191 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13192 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13193 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13194 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13195 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13196 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13197 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13198 | }; |
| 13199 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13200 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13201 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13202 | spdy::SpdySerializedFrame resp( |
| 13203 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13204 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13205 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13206 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13207 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13208 | }; |
| 13209 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13210 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13211 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13212 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13213 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13214 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13215 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13216 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13217 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13218 | &hanging_non_alternate_protocol_socket); |
| 13219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13220 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13223 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13224 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13225 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13226 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13228 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13229 | |
| 13230 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13231 | ASSERT_TRUE(response); |
| 13232 | ASSERT_TRUE(response->headers); |
| 13233 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13234 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13235 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13236 | |
| 13237 | std::string response_data; |
| 13238 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13239 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13241 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13244 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13246 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13247 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13248 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13249 | ASSERT_TRUE(response); |
| 13250 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13251 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13252 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13253 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13254 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13255 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13256 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13257 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13258 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13259 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13260 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13261 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13262 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13263 | LoadTimingInfo load_timing_info; |
| 13264 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13265 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13266 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13267 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13268 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13269 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13270 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13271 | HttpRequestInfo request; |
| 13272 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13273 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13274 | request.traffic_annotation = |
| 13275 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13276 | |
| 13277 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13278 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13279 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13280 | MockRead("\r\n"), |
| 13281 | MockRead("hello world"), |
| 13282 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13283 | }; |
| 13284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13285 | StaticSocketDataProvider first_transaction(data_reads, |
| 13286 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13287 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13288 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13289 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13291 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13292 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13293 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13294 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13295 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13296 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13297 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13298 | spdy::SpdySerializedFrame resp( |
| 13299 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13300 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13301 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13302 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13303 | }; |
| 13304 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13305 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13306 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13307 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13308 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13309 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13311 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13312 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13313 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13315 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13317 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13318 | |
| 13319 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13320 | ASSERT_TRUE(response); |
| 13321 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13322 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13323 | |
| 13324 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13325 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13326 | EXPECT_EQ("hello world", response_data); |
| 13327 | |
| 13328 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13329 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13330 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13331 | PRIVACY_MODE_DISABLED, |
| 13332 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13333 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13334 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13335 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13336 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13338 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13339 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13341 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13342 | |
| 13343 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13344 | ASSERT_TRUE(response); |
| 13345 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13346 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13347 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13348 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13349 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13350 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13351 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13352 | } |
| 13353 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13354 | // GenerateAuthToken is a mighty big test. |
| 13355 | // It tests all permutation of GenerateAuthToken behavior: |
| 13356 | // - Synchronous and Asynchronous completion. |
| 13357 | // - OK or error on completion. |
| 13358 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13359 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13360 | // - Non-authenticating and authenticating backend. |
| 13361 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13362 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13363 | // problems generating an auth token for an authenticating proxy, we don't |
| 13364 | // need to test all permutations of the backend server). |
| 13365 | // |
| 13366 | // The test proceeds by going over each of the configuration cases, and |
| 13367 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13368 | // specifies both the configuration for the test as well as the expectations |
| 13369 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13370 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13371 | static const char kServer[] = "http://www.example.com"; |
| 13372 | static const char kSecureServer[] = "https://www.example.com"; |
| 13373 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13374 | |
| 13375 | enum AuthTiming { |
| 13376 | AUTH_NONE, |
| 13377 | AUTH_SYNC, |
| 13378 | AUTH_ASYNC, |
| 13379 | }; |
| 13380 | |
| 13381 | const MockWrite kGet( |
| 13382 | "GET / HTTP/1.1\r\n" |
| 13383 | "Host: www.example.com\r\n" |
| 13384 | "Connection: keep-alive\r\n\r\n"); |
| 13385 | const MockWrite kGetProxy( |
| 13386 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13387 | "Host: www.example.com\r\n" |
| 13388 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13389 | const MockWrite kGetAuth( |
| 13390 | "GET / HTTP/1.1\r\n" |
| 13391 | "Host: www.example.com\r\n" |
| 13392 | "Connection: keep-alive\r\n" |
| 13393 | "Authorization: auth_token\r\n\r\n"); |
| 13394 | const MockWrite kGetProxyAuth( |
| 13395 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13396 | "Host: www.example.com\r\n" |
| 13397 | "Proxy-Connection: keep-alive\r\n" |
| 13398 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13399 | const MockWrite kGetAuthThroughProxy( |
| 13400 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13401 | "Host: www.example.com\r\n" |
| 13402 | "Proxy-Connection: keep-alive\r\n" |
| 13403 | "Authorization: auth_token\r\n\r\n"); |
| 13404 | const MockWrite kGetAuthWithProxyAuth( |
| 13405 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13406 | "Host: www.example.com\r\n" |
| 13407 | "Proxy-Connection: keep-alive\r\n" |
| 13408 | "Proxy-Authorization: auth_token\r\n" |
| 13409 | "Authorization: auth_token\r\n\r\n"); |
| 13410 | const MockWrite kConnect( |
| 13411 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13412 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13413 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13414 | const MockWrite kConnectProxyAuth( |
| 13415 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13416 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13417 | "Proxy-Connection: keep-alive\r\n" |
| 13418 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13419 | |
| 13420 | const MockRead kSuccess( |
| 13421 | "HTTP/1.1 200 OK\r\n" |
| 13422 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13423 | "Content-Length: 3\r\n\r\n" |
| 13424 | "Yes"); |
| 13425 | const MockRead kFailure( |
| 13426 | "Should not be called."); |
| 13427 | const MockRead kServerChallenge( |
| 13428 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13429 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13430 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13431 | "Content-Length: 14\r\n\r\n" |
| 13432 | "Unauthorized\r\n"); |
| 13433 | const MockRead kProxyChallenge( |
| 13434 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13435 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13436 | "Proxy-Connection: close\r\n" |
| 13437 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13438 | "Content-Length: 14\r\n\r\n" |
| 13439 | "Unauthorized\r\n"); |
| 13440 | const MockRead kProxyConnected( |
| 13441 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13442 | |
| 13443 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13444 | // no constructors, but the C++ compiler on Windows warns about |
| 13445 | // unspecified data in compound literals. So, moved to using constructors, |
| 13446 | // and TestRound's created with the default constructor should not be used. |
| 13447 | struct TestRound { |
| 13448 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13449 | : expected_rv(ERR_UNEXPECTED), |
| 13450 | extra_write(nullptr), |
| 13451 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13452 | TestRound(const MockWrite& write_arg, |
| 13453 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13454 | int expected_rv_arg) |
| 13455 | : write(write_arg), |
| 13456 | read(read_arg), |
| 13457 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13458 | extra_write(nullptr), |
| 13459 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13460 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13461 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13462 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13463 | : write(write_arg), |
| 13464 | read(read_arg), |
| 13465 | expected_rv(expected_rv_arg), |
| 13466 | extra_write(extra_write_arg), |
| 13467 | extra_read(extra_read_arg) { |
| 13468 | } |
| 13469 | MockWrite write; |
| 13470 | MockRead read; |
| 13471 | int expected_rv; |
| 13472 | const MockWrite* extra_write; |
| 13473 | const MockRead* extra_read; |
| 13474 | }; |
| 13475 | |
| 13476 | static const int kNoSSL = 500; |
| 13477 | |
| 13478 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13479 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13480 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13481 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13482 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13483 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13484 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13485 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13486 | int num_auth_rounds; |
| 13487 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13488 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13489 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13490 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13491 | {__LINE__, |
| 13492 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13493 | AUTH_NONE, |
| 13494 | OK, |
| 13495 | kServer, |
| 13496 | AUTH_NONE, |
| 13497 | OK, |
| 13498 | 1, |
| 13499 | kNoSSL, |
| 13500 | {TestRound(kGet, kSuccess, OK)}}, |
| 13501 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13502 | {__LINE__, |
| 13503 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13504 | AUTH_NONE, |
| 13505 | OK, |
| 13506 | kServer, |
| 13507 | AUTH_SYNC, |
| 13508 | OK, |
| 13509 | 2, |
| 13510 | kNoSSL, |
| 13511 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13512 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13513 | {__LINE__, |
| 13514 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13515 | AUTH_NONE, |
| 13516 | OK, |
| 13517 | kServer, |
| 13518 | AUTH_SYNC, |
| 13519 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13520 | 3, |
| 13521 | kNoSSL, |
| 13522 | {TestRound(kGet, kServerChallenge, OK), |
| 13523 | TestRound(kGet, kServerChallenge, OK), |
| 13524 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13525 | {__LINE__, |
| 13526 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13527 | AUTH_NONE, |
| 13528 | OK, |
| 13529 | kServer, |
| 13530 | AUTH_SYNC, |
| 13531 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13532 | 2, |
| 13533 | kNoSSL, |
| 13534 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13535 | {__LINE__, |
| 13536 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13537 | AUTH_NONE, |
| 13538 | OK, |
| 13539 | kServer, |
| 13540 | AUTH_SYNC, |
| 13541 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13542 | 2, |
| 13543 | kNoSSL, |
| 13544 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13545 | {__LINE__, |
| 13546 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13547 | AUTH_SYNC, |
| 13548 | ERR_FAILED, |
| 13549 | kServer, |
| 13550 | AUTH_NONE, |
| 13551 | OK, |
| 13552 | 2, |
| 13553 | kNoSSL, |
| 13554 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13555 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13556 | {__LINE__, |
| 13557 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13558 | AUTH_ASYNC, |
| 13559 | ERR_FAILED, |
| 13560 | kServer, |
| 13561 | AUTH_NONE, |
| 13562 | OK, |
| 13563 | 2, |
| 13564 | kNoSSL, |
| 13565 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13566 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13567 | {__LINE__, |
| 13568 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13569 | AUTH_NONE, |
| 13570 | OK, |
| 13571 | kServer, |
| 13572 | AUTH_SYNC, |
| 13573 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13574 | 2, |
| 13575 | kNoSSL, |
| 13576 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13577 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13578 | {__LINE__, |
| 13579 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13580 | AUTH_NONE, |
| 13581 | OK, |
| 13582 | kServer, |
| 13583 | AUTH_ASYNC, |
| 13584 | ERR_FAILED, |
| 13585 | 2, |
| 13586 | kNoSSL, |
| 13587 | {TestRound(kGet, kServerChallenge, OK), |
| 13588 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13589 | {__LINE__, |
| 13590 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13591 | AUTH_NONE, |
| 13592 | OK, |
| 13593 | kServer, |
| 13594 | AUTH_ASYNC, |
| 13595 | OK, |
| 13596 | 2, |
| 13597 | kNoSSL, |
| 13598 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13599 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13600 | {__LINE__, |
| 13601 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13602 | AUTH_NONE, |
| 13603 | OK, |
| 13604 | kServer, |
| 13605 | AUTH_ASYNC, |
| 13606 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13607 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13608 | kNoSSL, |
| 13609 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13610 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13611 | TestRound(kGet, kServerChallenge, OK), |
| 13612 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13613 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13614 | {__LINE__, |
| 13615 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13616 | AUTH_NONE, |
| 13617 | OK, |
| 13618 | kServer, |
| 13619 | AUTH_NONE, |
| 13620 | OK, |
| 13621 | 1, |
| 13622 | kNoSSL, |
| 13623 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13624 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13625 | {__LINE__, |
| 13626 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13627 | AUTH_NONE, |
| 13628 | OK, |
| 13629 | kServer, |
| 13630 | AUTH_SYNC, |
| 13631 | OK, |
| 13632 | 2, |
| 13633 | kNoSSL, |
| 13634 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13635 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13636 | {__LINE__, |
| 13637 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13638 | AUTH_NONE, |
| 13639 | OK, |
| 13640 | kServer, |
| 13641 | AUTH_SYNC, |
| 13642 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13643 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13644 | kNoSSL, |
| 13645 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13646 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13647 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13648 | {__LINE__, |
| 13649 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13650 | AUTH_NONE, |
| 13651 | OK, |
| 13652 | kServer, |
| 13653 | AUTH_ASYNC, |
| 13654 | OK, |
| 13655 | 2, |
| 13656 | kNoSSL, |
| 13657 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13658 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13659 | {__LINE__, |
| 13660 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13661 | AUTH_NONE, |
| 13662 | OK, |
| 13663 | kServer, |
| 13664 | AUTH_ASYNC, |
| 13665 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13666 | 2, |
| 13667 | kNoSSL, |
| 13668 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13669 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13670 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13671 | {__LINE__, |
| 13672 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13673 | AUTH_SYNC, |
| 13674 | OK, |
| 13675 | kServer, |
| 13676 | AUTH_NONE, |
| 13677 | OK, |
| 13678 | 2, |
| 13679 | kNoSSL, |
| 13680 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13681 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13682 | {__LINE__, |
| 13683 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13684 | AUTH_SYNC, |
| 13685 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13686 | kServer, |
| 13687 | AUTH_NONE, |
| 13688 | OK, |
| 13689 | 2, |
| 13690 | kNoSSL, |
| 13691 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13692 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13693 | {__LINE__, |
| 13694 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13695 | AUTH_ASYNC, |
| 13696 | OK, |
| 13697 | kServer, |
| 13698 | AUTH_NONE, |
| 13699 | OK, |
| 13700 | 2, |
| 13701 | kNoSSL, |
| 13702 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13703 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13704 | {__LINE__, |
| 13705 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13706 | AUTH_ASYNC, |
| 13707 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13708 | kServer, |
| 13709 | AUTH_NONE, |
| 13710 | OK, |
| 13711 | 2, |
| 13712 | kNoSSL, |
| 13713 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13714 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13715 | {__LINE__, |
| 13716 | kProxy, |
| 13717 | AUTH_ASYNC, |
| 13718 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13719 | kServer, |
| 13720 | AUTH_NONE, |
| 13721 | OK, |
| 13722 | 3, |
| 13723 | kNoSSL, |
| 13724 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13725 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13726 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13727 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13728 | {__LINE__, |
| 13729 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13730 | AUTH_SYNC, |
| 13731 | OK, |
| 13732 | kServer, |
| 13733 | AUTH_SYNC, |
| 13734 | OK, |
| 13735 | 3, |
| 13736 | kNoSSL, |
| 13737 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13738 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13739 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13740 | {__LINE__, |
| 13741 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13742 | AUTH_SYNC, |
| 13743 | OK, |
| 13744 | kServer, |
| 13745 | AUTH_SYNC, |
| 13746 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13747 | 3, |
| 13748 | kNoSSL, |
| 13749 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13750 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13751 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13752 | {__LINE__, |
| 13753 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13754 | AUTH_ASYNC, |
| 13755 | OK, |
| 13756 | kServer, |
| 13757 | AUTH_SYNC, |
| 13758 | OK, |
| 13759 | 3, |
| 13760 | kNoSSL, |
| 13761 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13762 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13763 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13764 | {__LINE__, |
| 13765 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13766 | AUTH_ASYNC, |
| 13767 | OK, |
| 13768 | kServer, |
| 13769 | AUTH_SYNC, |
| 13770 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13771 | 3, |
| 13772 | kNoSSL, |
| 13773 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13774 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13775 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13776 | {__LINE__, |
| 13777 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13778 | AUTH_SYNC, |
| 13779 | OK, |
| 13780 | kServer, |
| 13781 | AUTH_ASYNC, |
| 13782 | OK, |
| 13783 | 3, |
| 13784 | kNoSSL, |
| 13785 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13786 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13787 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13788 | {__LINE__, |
| 13789 | kProxy, |
| 13790 | AUTH_SYNC, |
| 13791 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13792 | kServer, |
| 13793 | AUTH_ASYNC, |
| 13794 | OK, |
| 13795 | 4, |
| 13796 | kNoSSL, |
| 13797 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13798 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13799 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13800 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13801 | {__LINE__, |
| 13802 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13803 | AUTH_SYNC, |
| 13804 | OK, |
| 13805 | kServer, |
| 13806 | AUTH_ASYNC, |
| 13807 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13808 | 3, |
| 13809 | kNoSSL, |
| 13810 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13811 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13812 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13813 | {__LINE__, |
| 13814 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13815 | AUTH_ASYNC, |
| 13816 | OK, |
| 13817 | kServer, |
| 13818 | AUTH_ASYNC, |
| 13819 | OK, |
| 13820 | 3, |
| 13821 | kNoSSL, |
| 13822 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13823 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13824 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13825 | {__LINE__, |
| 13826 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13827 | AUTH_ASYNC, |
| 13828 | OK, |
| 13829 | kServer, |
| 13830 | AUTH_ASYNC, |
| 13831 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13832 | 3, |
| 13833 | kNoSSL, |
| 13834 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13835 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13836 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13837 | {__LINE__, |
| 13838 | kProxy, |
| 13839 | AUTH_ASYNC, |
| 13840 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13841 | kServer, |
| 13842 | AUTH_ASYNC, |
| 13843 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13844 | 4, |
| 13845 | kNoSSL, |
| 13846 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13847 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13848 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13849 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13850 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13851 | {__LINE__, |
| 13852 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13853 | AUTH_NONE, |
| 13854 | OK, |
| 13855 | kSecureServer, |
| 13856 | AUTH_NONE, |
| 13857 | OK, |
| 13858 | 1, |
| 13859 | 0, |
| 13860 | {TestRound(kGet, kSuccess, OK)}}, |
| 13861 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13862 | {__LINE__, |
| 13863 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13864 | AUTH_NONE, |
| 13865 | OK, |
| 13866 | kSecureServer, |
| 13867 | AUTH_SYNC, |
| 13868 | OK, |
| 13869 | 2, |
| 13870 | 0, |
| 13871 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13872 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13873 | {__LINE__, |
| 13874 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13875 | AUTH_NONE, |
| 13876 | OK, |
| 13877 | kSecureServer, |
| 13878 | AUTH_SYNC, |
| 13879 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13880 | 2, |
| 13881 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13882 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13883 | {__LINE__, |
| 13884 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13885 | AUTH_NONE, |
| 13886 | OK, |
| 13887 | kSecureServer, |
| 13888 | AUTH_ASYNC, |
| 13889 | OK, |
| 13890 | 2, |
| 13891 | 0, |
| 13892 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13893 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13894 | {__LINE__, |
| 13895 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13896 | AUTH_NONE, |
| 13897 | OK, |
| 13898 | kSecureServer, |
| 13899 | AUTH_ASYNC, |
| 13900 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13901 | 2, |
| 13902 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13903 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13904 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13905 | {__LINE__, |
| 13906 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13907 | AUTH_NONE, |
| 13908 | OK, |
| 13909 | kSecureServer, |
| 13910 | AUTH_NONE, |
| 13911 | OK, |
| 13912 | 1, |
| 13913 | 0, |
| 13914 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13915 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13916 | {__LINE__, |
| 13917 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13918 | AUTH_NONE, |
| 13919 | OK, |
| 13920 | kSecureServer, |
| 13921 | AUTH_SYNC, |
| 13922 | OK, |
| 13923 | 2, |
| 13924 | 0, |
| 13925 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13926 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13927 | {__LINE__, |
| 13928 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13929 | AUTH_NONE, |
| 13930 | OK, |
| 13931 | kSecureServer, |
| 13932 | AUTH_SYNC, |
| 13933 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13934 | 2, |
| 13935 | 0, |
| 13936 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13937 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13938 | {__LINE__, |
| 13939 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13940 | AUTH_NONE, |
| 13941 | OK, |
| 13942 | kSecureServer, |
| 13943 | AUTH_ASYNC, |
| 13944 | OK, |
| 13945 | 2, |
| 13946 | 0, |
| 13947 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13948 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13949 | {__LINE__, |
| 13950 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13951 | AUTH_NONE, |
| 13952 | OK, |
| 13953 | kSecureServer, |
| 13954 | AUTH_ASYNC, |
| 13955 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13956 | 2, |
| 13957 | 0, |
| 13958 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13959 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13960 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13961 | {__LINE__, |
| 13962 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13963 | AUTH_SYNC, |
| 13964 | OK, |
| 13965 | kSecureServer, |
| 13966 | AUTH_NONE, |
| 13967 | OK, |
| 13968 | 2, |
| 13969 | 1, |
| 13970 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13971 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13972 | {__LINE__, |
| 13973 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13974 | AUTH_SYNC, |
| 13975 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13976 | kSecureServer, |
| 13977 | AUTH_NONE, |
| 13978 | OK, |
| 13979 | 2, |
| 13980 | kNoSSL, |
| 13981 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13982 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13983 | {__LINE__, |
| 13984 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13985 | AUTH_SYNC, |
| 13986 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13987 | kSecureServer, |
| 13988 | AUTH_NONE, |
| 13989 | OK, |
| 13990 | 2, |
| 13991 | kNoSSL, |
| 13992 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13993 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13994 | {__LINE__, |
| 13995 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13996 | AUTH_SYNC, |
| 13997 | ERR_UNEXPECTED, |
| 13998 | kSecureServer, |
| 13999 | AUTH_NONE, |
| 14000 | OK, |
| 14001 | 2, |
| 14002 | kNoSSL, |
| 14003 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14004 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14005 | {__LINE__, |
| 14006 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14007 | AUTH_ASYNC, |
| 14008 | OK, |
| 14009 | kSecureServer, |
| 14010 | AUTH_NONE, |
| 14011 | OK, |
| 14012 | 2, |
| 14013 | 1, |
| 14014 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14015 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14016 | {__LINE__, |
| 14017 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14018 | AUTH_ASYNC, |
| 14019 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14020 | kSecureServer, |
| 14021 | AUTH_NONE, |
| 14022 | OK, |
| 14023 | 2, |
| 14024 | kNoSSL, |
| 14025 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14026 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14027 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14028 | {__LINE__, |
| 14029 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14030 | AUTH_SYNC, |
| 14031 | OK, |
| 14032 | kSecureServer, |
| 14033 | AUTH_SYNC, |
| 14034 | OK, |
| 14035 | 3, |
| 14036 | 1, |
| 14037 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14038 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14039 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14040 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14041 | {__LINE__, |
| 14042 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14043 | AUTH_SYNC, |
| 14044 | OK, |
| 14045 | kSecureServer, |
| 14046 | AUTH_SYNC, |
| 14047 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14048 | 3, |
| 14049 | 1, |
| 14050 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14051 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14052 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14053 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14054 | {__LINE__, |
| 14055 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14056 | AUTH_ASYNC, |
| 14057 | OK, |
| 14058 | kSecureServer, |
| 14059 | AUTH_SYNC, |
| 14060 | OK, |
| 14061 | 3, |
| 14062 | 1, |
| 14063 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14064 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14065 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14066 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14067 | {__LINE__, |
| 14068 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14069 | AUTH_ASYNC, |
| 14070 | OK, |
| 14071 | kSecureServer, |
| 14072 | AUTH_SYNC, |
| 14073 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14074 | 3, |
| 14075 | 1, |
| 14076 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14077 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14078 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14079 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14080 | {__LINE__, |
| 14081 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14082 | AUTH_SYNC, |
| 14083 | OK, |
| 14084 | kSecureServer, |
| 14085 | AUTH_ASYNC, |
| 14086 | OK, |
| 14087 | 3, |
| 14088 | 1, |
| 14089 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14090 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14091 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14092 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14093 | {__LINE__, |
| 14094 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14095 | AUTH_SYNC, |
| 14096 | OK, |
| 14097 | kSecureServer, |
| 14098 | AUTH_ASYNC, |
| 14099 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14100 | 3, |
| 14101 | 1, |
| 14102 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14103 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14104 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14105 | TestRound(kGet, 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_ASYNC, |
| 14109 | OK, |
| 14110 | kSecureServer, |
| 14111 | AUTH_ASYNC, |
| 14112 | OK, |
| 14113 | 3, |
| 14114 | 1, |
| 14115 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14116 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14117 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14118 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14119 | {__LINE__, |
| 14120 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14121 | AUTH_ASYNC, |
| 14122 | OK, |
| 14123 | kSecureServer, |
| 14124 | AUTH_ASYNC, |
| 14125 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14126 | 3, |
| 14127 | 1, |
| 14128 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14129 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14130 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14131 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14132 | {__LINE__, |
| 14133 | kProxy, |
| 14134 | AUTH_ASYNC, |
| 14135 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14136 | kSecureServer, |
| 14137 | AUTH_ASYNC, |
| 14138 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14139 | 4, |
| 14140 | 2, |
| 14141 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14142 | TestRound(kConnect, kProxyChallenge, OK), |
| 14143 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14144 | &kServerChallenge), |
| 14145 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14146 | }; |
| 14147 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14148 | for (const auto& test_config : test_configs) { |
| 14149 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14150 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14151 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14152 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14153 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14154 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14155 | |
| 14156 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14157 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14158 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14159 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14160 | std::string auth_challenge = "Mock realm=proxy"; |
| 14161 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14162 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14163 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14164 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14165 | empty_ssl_info, origin, |
| 14166 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14167 | auth_handler->SetGenerateExpectation( |
| 14168 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14169 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14170 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14171 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14172 | } |
| 14173 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14174 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14175 | std::string auth_challenge = "Mock realm=server"; |
| 14176 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14177 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14178 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14179 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14180 | empty_ssl_info, origin, |
| 14181 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14182 | auth_handler->SetGenerateExpectation( |
| 14183 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14184 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14185 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14186 | |
| 14187 | // The second handler always succeeds. It should only be used where there |
| 14188 | // are multiple auth sessions for server auth in the same network |
| 14189 | // transaction using the same auth scheme. |
| 14190 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14191 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14192 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14193 | empty_ssl_info, origin, |
| 14194 | NetLogWithSource()); |
| 14195 | second_handler->SetGenerateExpectation(true, OK); |
| 14196 | auth_factory->AddMockHandler(second_handler.release(), |
| 14197 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14198 | } |
| 14199 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14200 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14201 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14202 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14203 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14204 | session_deps_.proxy_resolution_service = |
| 14205 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14206 | } |
| 14207 | |
| 14208 | HttpRequestInfo request; |
| 14209 | request.method = "GET"; |
| 14210 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14211 | request.traffic_annotation = |
| 14212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14213 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14215 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14216 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14217 | |
| 14218 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14219 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14220 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14221 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14222 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14223 | |
| 14224 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14225 | mock_reads.back().push_back(read_write_round.read); |
| 14226 | mock_writes.back().push_back(read_write_round.write); |
| 14227 | |
| 14228 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14229 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14230 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14231 | mock_reads.push_back(std::vector<MockRead>()); |
| 14232 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14233 | } |
| 14234 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14235 | if (read_write_round.extra_read) { |
| 14236 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14237 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14238 | if (read_write_round.extra_write) { |
| 14239 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14240 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14241 | |
| 14242 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14243 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14244 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14245 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14246 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14247 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14248 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14249 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14250 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14251 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14252 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14253 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14254 | } |
| 14255 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14256 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14257 | // they are as well. |
| 14258 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14259 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14260 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14261 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14262 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14263 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14264 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14265 | int rv; |
| 14266 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14267 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14268 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14269 | rv = trans.RestartWithAuth( |
| 14270 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14271 | } |
| 14272 | if (rv == ERR_IO_PENDING) |
| 14273 | rv = callback.WaitForResult(); |
| 14274 | |
| 14275 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14276 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14277 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14278 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14279 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14280 | continue; |
| 14281 | } |
| 14282 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14283 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14284 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14285 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14286 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14287 | } |
| 14288 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14289 | } |
| 14290 | } |
| 14291 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14292 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14293 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14294 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14295 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14296 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14297 | session_deps_.proxy_resolution_service = |
| 14298 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14299 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14300 | |
| 14301 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14302 | auth_handler->set_connection_based(true); |
| 14303 | std::string auth_challenge = "Mock realm=server"; |
| 14304 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14305 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14306 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14307 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14308 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14309 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14310 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14311 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14312 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14313 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14314 | HttpRequestInfo request; |
| 14315 | request.method = "GET"; |
| 14316 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14317 | request.traffic_annotation = |
| 14318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14319 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14320 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14321 | |
| 14322 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14323 | // to validate that the TCP socket is not released to the pool between |
| 14324 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14325 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14326 | CommonConnectJobParams common_connect_job_params( |
| 14327 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14328 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14329 | 50, // Max sockets for pool |
| 14330 | 1, // Max sockets per group |
| 14331 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame] | 14332 | ProxyServer::Direct(), false, // is_for_websockets |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14333 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14334 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14335 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14336 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14337 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14340 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14341 | |
| 14342 | const MockWrite kGet( |
| 14343 | "GET / HTTP/1.1\r\n" |
| 14344 | "Host: www.example.com\r\n" |
| 14345 | "Connection: keep-alive\r\n\r\n"); |
| 14346 | const MockWrite kGetAuth( |
| 14347 | "GET / HTTP/1.1\r\n" |
| 14348 | "Host: www.example.com\r\n" |
| 14349 | "Connection: keep-alive\r\n" |
| 14350 | "Authorization: auth_token\r\n\r\n"); |
| 14351 | |
| 14352 | const MockRead kServerChallenge( |
| 14353 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14354 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14355 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14356 | "Content-Length: 14\r\n\r\n" |
| 14357 | "Unauthorized\r\n"); |
| 14358 | const MockRead kSuccess( |
| 14359 | "HTTP/1.1 200 OK\r\n" |
| 14360 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14361 | "Content-Length: 3\r\n\r\n" |
| 14362 | "Yes"); |
| 14363 | |
| 14364 | MockWrite writes[] = { |
| 14365 | // First round |
| 14366 | kGet, |
| 14367 | // Second round |
| 14368 | kGetAuth, |
| 14369 | // Third round |
| 14370 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14371 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14372 | kGetAuth, |
| 14373 | // Competing request |
| 14374 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14375 | }; |
| 14376 | MockRead reads[] = { |
| 14377 | // First round |
| 14378 | kServerChallenge, |
| 14379 | // Second round |
| 14380 | kServerChallenge, |
| 14381 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14382 | kServerChallenge, |
| 14383 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14384 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14385 | // Competing response |
| 14386 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14387 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14388 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14389 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14390 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14391 | const ClientSocketPool::GroupId kSocketGroup( |
| 14392 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 14393 | PrivacyMode::PRIVACY_MODE_DISABLED); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14394 | |
| 14395 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14396 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14397 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14398 | if (rv == ERR_IO_PENDING) |
| 14399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14400 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14401 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14402 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14403 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14404 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14405 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14406 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14407 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14408 | // In between rounds, another request comes in for the same domain. |
| 14409 | // It should not be able to grab the TCP socket that trans has already |
| 14410 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14411 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14412 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14413 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14414 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14416 | // callback_compete.WaitForResult at this point would stall forever, |
| 14417 | // since the HttpNetworkTransaction does not release the request back to |
| 14418 | // the pool until after authentication completes. |
| 14419 | |
| 14420 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14421 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14422 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14423 | if (rv == ERR_IO_PENDING) |
| 14424 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14425 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14426 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14427 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14428 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14429 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14430 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14431 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14432 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14433 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14434 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14435 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14436 | if (rv == ERR_IO_PENDING) |
| 14437 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14438 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14439 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14440 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14441 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14442 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14443 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14444 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14445 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14446 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14447 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14448 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14449 | if (rv == ERR_IO_PENDING) |
| 14450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14451 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14452 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14453 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14454 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14455 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14456 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14457 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14458 | // auth handler should transition to a DONE state in concert with the remote |
| 14459 | // server. But that's not something we can test here with a mock handler. |
| 14460 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14461 | auth_handler->state()); |
| 14462 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14463 | // Read the body since the fourth round was successful. This will also |
| 14464 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14465 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14466 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14467 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14468 | if (rv == ERR_IO_PENDING) |
| 14469 | rv = callback.WaitForResult(); |
| 14470 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14471 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14472 | EXPECT_EQ(0, rv); |
| 14473 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14474 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14475 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14476 | |
| 14477 | // The competing request can now finish. Wait for the headers and then |
| 14478 | // read the body. |
| 14479 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14480 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14481 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14482 | if (rv == ERR_IO_PENDING) |
| 14483 | rv = callback.WaitForResult(); |
| 14484 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14485 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14486 | EXPECT_EQ(0, rv); |
| 14487 | |
| 14488 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14489 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14490 | } |
| 14491 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14492 | // This tests the case that a request is issued via http instead of spdy after |
| 14493 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14494 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14495 | HttpRequestInfo request; |
| 14496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14497 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14498 | request.traffic_annotation = |
| 14499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14500 | |
| 14501 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14502 | MockWrite( |
| 14503 | "GET / HTTP/1.1\r\n" |
| 14504 | "Host: www.example.org\r\n" |
| 14505 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14506 | }; |
| 14507 | |
| 14508 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14509 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14510 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14511 | MockRead("\r\n"), |
| 14512 | MockRead("hello world"), |
| 14513 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14514 | }; |
| 14515 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14516 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14517 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14518 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14520 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14521 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14522 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14523 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14524 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14529 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14530 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14532 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14535 | ASSERT_TRUE(response); |
| 14536 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14538 | |
| 14539 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14540 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14541 | EXPECT_EQ("hello world", response_data); |
| 14542 | |
| 14543 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14544 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14545 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14546 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14547 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14548 | // immediate server closing of the socket. |
| 14549 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14550 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14551 | HttpRequestInfo request; |
| 14552 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14553 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14554 | request.traffic_annotation = |
| 14555 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14556 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14557 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14558 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14559 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14560 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14561 | spdy::SpdySerializedFrame req( |
| 14562 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14563 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14564 | |
| 14565 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14566 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14567 | }; |
| 14568 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14569 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14570 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14571 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14572 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14576 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14577 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14578 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14579 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14580 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14581 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14582 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14583 | // it gets it. This is needed since the auth handler may get destroyed |
| 14584 | // before we get a chance to query it. |
| 14585 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14586 | public: |
| 14587 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14588 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14589 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14590 | |
| 14591 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14592 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14593 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14594 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14595 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14596 | *url_ = request->url; |
| 14597 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14598 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14599 | } |
| 14600 | |
| 14601 | private: |
| 14602 | GURL* url_; |
| 14603 | }; |
| 14604 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14605 | // Test that if we cancel the transaction as the connection is completing, that |
| 14606 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14607 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14608 | // Setup everything about the connection to complete synchronously, so that |
| 14609 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14610 | // for is the callback from the HttpStreamRequest. |
| 14611 | // Then cancel the transaction. |
| 14612 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14613 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14614 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14615 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14616 | MockRead(SYNCHRONOUS, "hello world"), |
| 14617 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14618 | }; |
| 14619 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14620 | HttpRequestInfo request; |
| 14621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14622 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14623 | request.traffic_annotation = |
| 14624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14627 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14628 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14629 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14630 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14631 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14634 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14635 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14636 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14637 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14639 | trans.reset(); // Cancel the transaction here. |
| 14640 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14641 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14642 | } |
| 14643 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14644 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14645 | // stream is drained properly and added back to the socket pool. The main |
| 14646 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14647 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14648 | // deleted. |
| 14649 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14650 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14651 | MockRead data_reads[] = { |
| 14652 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14653 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14654 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14655 | MockRead(ASYNC, "1"), |
| 14656 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14657 | // HttpNetworkTransaction has been deleted. |
| 14658 | MockRead(ASYNC, "2"), |
| 14659 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14660 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14661 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14662 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14663 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14665 | |
| 14666 | { |
| 14667 | HttpRequestInfo request; |
| 14668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14669 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14670 | request.traffic_annotation = |
| 14671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14672 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14674 | TestCompletionCallback callback; |
| 14675 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14676 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14678 | callback.WaitForResult(); |
| 14679 | |
| 14680 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14681 | ASSERT_TRUE(response); |
| 14682 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14683 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14684 | |
| 14685 | // The transaction and HttpRequestInfo are deleted. |
| 14686 | } |
| 14687 | |
| 14688 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14689 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14690 | |
| 14691 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14692 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14693 | } |
| 14694 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14695 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14696 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14697 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14698 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14699 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14700 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14701 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14702 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14703 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14704 | HttpRequestInfo request; |
| 14705 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14706 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14707 | request.traffic_annotation = |
| 14708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14709 | |
| 14710 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14711 | MockWrite( |
| 14712 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14713 | "Host: www.example.org\r\n" |
| 14714 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14715 | }; |
| 14716 | |
| 14717 | MockRead data_reads1[] = { |
| 14718 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14719 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14720 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14722 | }; |
| 14723 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14724 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14725 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14727 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14730 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14731 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14732 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14733 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14735 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14737 | |
| 14738 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14741 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14742 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14743 | |
| 14744 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14745 | EXPECT_EQ(200, response->headers->response_code()); |
| 14746 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14747 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14748 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14749 | HostPortPair::FromString("myproxy:70")), |
| 14750 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14751 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14752 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14753 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14754 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14755 | |
| 14756 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14757 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14758 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14759 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14760 | } |
| 14761 | |
| 14762 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14763 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14764 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14765 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14766 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14767 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14768 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14770 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14771 | HttpRequestInfo request; |
| 14772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14773 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14774 | request.traffic_annotation = |
| 14775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14776 | |
| 14777 | // Since we have proxy, should try to establish tunnel. |
| 14778 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14779 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14780 | "Host: www.example.org:443\r\n" |
| 14781 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14782 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14783 | MockWrite("GET / HTTP/1.1\r\n" |
| 14784 | "Host: www.example.org\r\n" |
| 14785 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14786 | }; |
| 14787 | |
| 14788 | MockRead data_reads1[] = { |
| 14789 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14790 | |
| 14791 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14792 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14793 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14795 | }; |
| 14796 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14797 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14798 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14799 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14802 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14805 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14806 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14807 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14808 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14810 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14812 | |
| 14813 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14814 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14815 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14816 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14817 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14818 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14819 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14820 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14821 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14822 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14823 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14825 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14826 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14827 | |
| 14828 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14829 | EXPECT_EQ(200, response->headers->response_code()); |
| 14830 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14831 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14832 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14833 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14834 | HostPortPair::FromString("myproxy:70")), |
| 14835 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14836 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14837 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14838 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14839 | |
| 14840 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14841 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14842 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14843 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14844 | } |
| 14845 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14846 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14847 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14848 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14849 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14850 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14851 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14852 | BoundTestNetLog log; |
| 14853 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14855 | |
| 14856 | HttpRequestInfo request; |
| 14857 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14858 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14859 | request.traffic_annotation = |
| 14860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14861 | |
| 14862 | // Since we have proxy, should try to establish tunnel. |
| 14863 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14864 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14865 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14866 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14867 | |
| 14868 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14869 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14870 | "Connection: keep-alive\r\n\r\n"), |
| 14871 | }; |
| 14872 | |
| 14873 | MockRead data_reads1[] = { |
| 14874 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14875 | |
| 14876 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14877 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14878 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14879 | MockRead(SYNCHRONOUS, OK), |
| 14880 | }; |
| 14881 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14882 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14884 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14886 | |
| 14887 | TestCompletionCallback callback1; |
| 14888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14891 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14893 | |
| 14894 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14895 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14896 | TestNetLogEntry::List entries; |
| 14897 | log.GetEntries(&entries); |
| 14898 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14899 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14900 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14901 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14902 | entries, pos, |
| 14903 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14904 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14906 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14907 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14908 | |
| 14909 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14910 | EXPECT_EQ(200, response->headers->response_code()); |
| 14911 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14912 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14913 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14914 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14915 | HostPortPair::FromString("myproxy:70")), |
| 14916 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14917 | |
| 14918 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14919 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14920 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14921 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14922 | } |
| 14923 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14924 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14925 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14926 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14927 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14928 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14929 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14930 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14932 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14933 | HttpRequestInfo request; |
| 14934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14935 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14936 | request.traffic_annotation = |
| 14937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14938 | |
| 14939 | // Since we have proxy, should try to establish tunnel. |
| 14940 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14941 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14942 | "Host: www.example.org:443\r\n" |
| 14943 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14944 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14945 | MockWrite("GET / HTTP/1.1\r\n" |
| 14946 | "Host: www.example.org\r\n" |
| 14947 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14948 | }; |
| 14949 | |
| 14950 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14951 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14952 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14953 | }; |
| 14954 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14955 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14956 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14957 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14959 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14960 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14962 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14964 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14966 | |
| 14967 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14968 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14969 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14970 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14971 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14972 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14973 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14974 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14975 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14976 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14977 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14978 | } |
| 14979 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14980 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14981 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14982 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14983 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14984 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14985 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14986 | spdy::SpdySerializedFrame resp( |
| 14987 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14988 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14989 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14990 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14991 | }; |
| 14992 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14993 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14994 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14995 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14996 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14997 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14998 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14999 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15001 | |
| 15002 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15003 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15004 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15005 | PRIVACY_MODE_DISABLED, |
| 15006 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15007 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15008 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15009 | |
| 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] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15016 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15017 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15018 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15021 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15022 | } |
| 15023 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15024 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15025 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15026 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15027 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15028 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15029 | request_info.url = GURL("https://www.example.com/"); |
| 15030 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15031 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15032 | request_info.traffic_annotation = |
| 15033 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15034 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15035 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15036 | MockWrite data_writes[] = { |
| 15037 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15038 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15039 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15040 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15041 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15042 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15043 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15046 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15047 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15048 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15049 | rv = callback.WaitForResult(); |
| 15050 | ASSERT_EQ(error, rv); |
| 15051 | } |
| 15052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15053 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15054 | // Just check a grab bag of cert errors. |
| 15055 | static const int kErrors[] = { |
| 15056 | ERR_CERT_COMMON_NAME_INVALID, |
| 15057 | ERR_CERT_AUTHORITY_INVALID, |
| 15058 | ERR_CERT_DATE_INVALID, |
| 15059 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15060 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15061 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15062 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15063 | } |
| 15064 | } |
| 15065 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15066 | // Ensure that a client certificate is removed from the SSL client auth |
| 15067 | // cache when: |
| 15068 | // 1) No proxy is involved. |
| 15069 | // 2) TLS False Start is disabled. |
| 15070 | // 3) The initial TLS handshake requests a client certificate. |
| 15071 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15072 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15073 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15074 | request_info.url = GURL("https://www.example.com/"); |
| 15075 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15076 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15077 | request_info.traffic_annotation = |
| 15078 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15079 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15080 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15081 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15082 | |
| 15083 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15084 | // CertificateRequest is received for the first time, the handshake will |
| 15085 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15086 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15087 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15089 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15090 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15091 | |
| 15092 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15093 | // False Start is not being used, the result of the SSL handshake will be |
| 15094 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15095 | // matches the result of a server sending a handshake_failure alert, |
| 15096 | // rather than a Finished message, because it requires a client |
| 15097 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15098 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15099 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15101 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15102 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15103 | |
| 15104 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15105 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15106 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15107 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15108 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15109 | // requiring a client certificate, this fallback handshake should also |
| 15110 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15111 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15112 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15113 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15115 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15116 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15117 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15118 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15119 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15120 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15121 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15122 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15123 | // requiring a client certificate, this fallback handshake should also |
| 15124 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15125 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15126 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15128 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15129 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15130 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15133 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15134 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15135 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15136 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15137 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15138 | |
| 15139 | // Complete the SSL handshake, which should abort due to requiring a |
| 15140 | // client certificate. |
| 15141 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15142 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15143 | |
| 15144 | // Indicate that no certificate should be supplied. From the perspective |
| 15145 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15146 | // certificate, so this is the same as supply a |
| 15147 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15148 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15149 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15150 | |
| 15151 | // Ensure the certificate was added to the client auth cache before |
| 15152 | // allowing the connection to continue restarting. |
| 15153 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15154 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15155 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15156 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15157 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15158 | |
| 15159 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15160 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15161 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15162 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15163 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15164 | |
| 15165 | // Ensure that the client certificate is removed from the cache on a |
| 15166 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15167 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15168 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15169 | } |
| 15170 | |
| 15171 | // Ensure that a client certificate is removed from the SSL client auth |
| 15172 | // cache when: |
| 15173 | // 1) No proxy is involved. |
| 15174 | // 2) TLS False Start is enabled. |
| 15175 | // 3) The initial TLS handshake requests a client certificate. |
| 15176 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15177 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15178 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15179 | request_info.url = GURL("https://www.example.com/"); |
| 15180 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15181 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15182 | request_info.traffic_annotation = |
| 15183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15184 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15185 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15186 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15187 | |
| 15188 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15189 | // return successfully after reading up to the peer's Certificate message. |
| 15190 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15191 | // enqueue application data to be sent in the same packet as the |
| 15192 | // ChangeCipherSpec and Finished messages. |
| 15193 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15194 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15195 | // Finished messages. If there was an error negotiating with the peer, |
| 15196 | // such as due to the peer requiring a client certificate when none was |
| 15197 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15198 | // called. |
| 15199 | |
| 15200 | // Like the non-False Start case, when a client certificate is requested by |
| 15201 | // the peer, the handshake is aborted during the Connect() call. |
| 15202 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15203 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15204 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15206 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15207 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15208 | |
| 15209 | // When a client certificate is supplied, Connect() will not be aborted |
| 15210 | // when the peer requests the certificate. Instead, the handshake will |
| 15211 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15212 | // the socket. The handshake messages are not processed until Read() is |
| 15213 | // called, which then detects that the handshake was aborted, due to the |
| 15214 | // peer sending a handshake_failure because it requires a client |
| 15215 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15216 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15217 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15218 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15219 | MockRead data2_reads[] = { |
| 15220 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15221 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15222 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15223 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15224 | |
| 15225 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15226 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15227 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15228 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15229 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15230 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15231 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15232 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15233 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15234 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15235 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15236 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15237 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15239 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15240 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15241 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15242 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15243 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15244 | ssl_data5.cert_request_info = cert_request.get(); |
| 15245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15246 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15247 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15250 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15251 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15252 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15253 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15254 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15255 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15256 | |
| 15257 | // Complete the SSL handshake, which should abort due to requiring a |
| 15258 | // client certificate. |
| 15259 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15260 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15261 | |
| 15262 | // Indicate that no certificate should be supplied. From the perspective |
| 15263 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15264 | // certificate, so this is the same as supply a |
| 15265 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15266 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15267 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15268 | |
| 15269 | // Ensure the certificate was added to the client auth cache before |
| 15270 | // allowing the connection to continue restarting. |
| 15271 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15272 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15273 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15274 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15275 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15276 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15277 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15278 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15279 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15280 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15281 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15282 | |
| 15283 | // Ensure that the client certificate is removed from the cache on a |
| 15284 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15285 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15286 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15287 | } |
| 15288 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15289 | // Ensure that a client certificate is removed from the SSL client auth |
| 15290 | // cache when: |
| 15291 | // 1) An HTTPS proxy is involved. |
| 15292 | // 3) The HTTPS proxy requests a client certificate. |
| 15293 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15294 | // proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15295 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15296 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15297 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15298 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15299 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15300 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15301 | auto cert_request = base::MakeRefCounted<SSLCertRequestInfo>(); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15302 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15303 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15304 | // Repeat the test for connecting to an HTTPS endpoint, then for connecting to |
| 15305 | // an HTTP endpoint. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15306 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15307 | requests[0].url = GURL("https://www.example.com/"); |
| 15308 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15309 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15310 | requests[0].traffic_annotation = |
| 15311 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15312 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15313 | // HTTPS requests are tunneled. |
| 15314 | MockWrite https_writes[] = { |
| 15315 | MockWrite("CONNECT www.example.com:443 HTTP/1.1\r\n" |
| 15316 | "Host: www.example.com:443\r\n" |
| 15317 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15318 | }; |
| 15319 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15320 | requests[1].url = GURL("http://www.example.com/"); |
| 15321 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15322 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15323 | requests[1].traffic_annotation = |
| 15324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15325 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15326 | // HTTP requests are not. |
| 15327 | MockWrite http_writes[] = { |
| 15328 | MockWrite("GET http://www.example.com/ HTTP/1.1\r\n" |
| 15329 | "Host: www.example.com\r\n" |
| 15330 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 15331 | }; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15332 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15333 | // When the server rejects the client certificate, it will close the |
| 15334 | // connection. In TLS 1.2, this is signaled out of Connect(). In TLS 1.3 (or |
| 15335 | // TLS 1.2 with False Start), the error is returned out of the first Read(). |
| 15336 | for (bool reject_in_connect : {true, false}) { |
| 15337 | SCOPED_TRACE(reject_in_connect); |
| 15338 | // Client certificate errors are typically signaled with |
| 15339 | // ERR_BAD_SSL_CLIENT_AUTH_CERT, but sometimes the server gives an arbitrary |
| 15340 | // protocol error. |
| 15341 | for (Error reject_error : |
| 15342 | {ERR_SSL_PROTOCOL_ERROR, ERR_BAD_SSL_CLIENT_AUTH_CERT}) { |
| 15343 | SCOPED_TRACE(reject_error); |
| 15344 | // Tunneled and non-tunneled requests are handled differently. Test both. |
| 15345 | for (const HttpRequestInfo& request : requests) { |
| 15346 | SCOPED_TRACE(request.url); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15347 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15348 | session_deps_.socket_factory = |
| 15349 | std::make_unique<MockClientSocketFactory>(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15350 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15351 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15352 | // [ssl_]data[1-2]. [ssl_]data3 is not needed because we do not retry |
| 15353 | // for proxies. Rather than represending the endpoint |
| 15354 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15355 | // (proxy:70). |
| 15356 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 15357 | ssl_data1.cert_request_info = cert_request.get(); |
| 15358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
| 15359 | StaticSocketDataProvider data1; |
| 15360 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15361 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15362 | base::Optional<SSLSocketDataProvider> ssl_data2; |
| 15363 | base::Optional<StaticSocketDataProvider> data2; |
| 15364 | MockRead error_in_read[] = {MockRead(ASYNC, reject_error)}; |
| 15365 | if (reject_in_connect) { |
| 15366 | ssl_data2.emplace(ASYNC, reject_error); |
| 15367 | // There are no reads or writes. |
| 15368 | data2.emplace(); |
| 15369 | } else { |
| 15370 | ssl_data2.emplace(ASYNC, OK); |
| 15371 | // We will get one Write() in before observing the error in Read(). |
| 15372 | if (request.url.SchemeIsCryptographic()) { |
| 15373 | data2.emplace(error_in_read, https_writes); |
| 15374 | } else { |
| 15375 | data2.emplace(error_in_read, http_writes); |
| 15376 | } |
| 15377 | } |
| 15378 | ssl_data2->cert_request_info = cert_request.get(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15379 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15380 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
| 15381 | &ssl_data2.value()); |
| 15382 | session_deps_.socket_factory->AddSocketDataProvider(&data2.value()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15383 | |
David Benjamin | 3b94b0f | 2019-04-25 23:07:52 | [diff] [blame] | 15384 | std::unique_ptr<HttpNetworkSession> session = |
| 15385 | CreateSession(&session_deps_); |
| 15386 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 15387 | |
| 15388 | // Begin the SSL handshake with the proxy. |
| 15389 | TestCompletionCallback callback; |
| 15390 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 15391 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15392 | |
| 15393 | // Complete the SSL handshake, which should abort due to requiring a |
| 15394 | // client certificate. |
| 15395 | rv = callback.WaitForResult(); |
| 15396 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 15397 | |
| 15398 | // Indicate that no certificate should be supplied. From the |
| 15399 | // perspective of SSLClientCertCache, NULL is just as meaningful as a |
| 15400 | // real certificate, so this is the same as supply a |
| 15401 | // legitimate-but-unacceptable certificate. |
| 15402 | rv = |
| 15403 | trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
| 15404 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15405 | |
| 15406 | // Ensure the certificate was added to the client auth cache before |
| 15407 | // allowing the connection to continue restarting. |
| 15408 | scoped_refptr<X509Certificate> client_cert; |
| 15409 | scoped_refptr<SSLPrivateKey> client_private_key; |
| 15410 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
| 15411 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15412 | ASSERT_FALSE(client_cert); |
| 15413 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15414 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
| 15415 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15416 | HostPortPair("www.example.com", 443), &client_cert, |
| 15417 | &client_private_key)); |
| 15418 | |
| 15419 | // Restart the handshake. This will consume ssl_data2. The result code |
| 15420 | // is checked against what ssl_data2 should return. |
| 15421 | rv = callback.WaitForResult(); |
| 15422 | ASSERT_THAT(rv, AnyOf(IsError(ERR_PROXY_CONNECTION_FAILED), |
| 15423 | IsError(reject_error))); |
| 15424 | |
| 15425 | // Now that the new handshake has failed, ensure that the client |
| 15426 | // certificate was removed from the client auth cache. |
| 15427 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15428 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
| 15429 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
| 15430 | HostPortPair("www.example.com", 443), &client_cert, |
| 15431 | &client_private_key)); |
| 15432 | } |
| 15433 | } |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15434 | } |
| 15435 | } |
| 15436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15437 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15438 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15439 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15441 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15442 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15443 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15444 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15445 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15446 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15447 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15448 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15449 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15450 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15451 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15452 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15453 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15454 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15455 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15456 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15457 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15458 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15459 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15460 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15461 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15462 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15463 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15464 | }; |
| 15465 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15466 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15467 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15468 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15469 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15470 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15471 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15472 | HttpRequestInfo request1; |
| 15473 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15474 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15475 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15476 | request1.traffic_annotation = |
| 15477 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15478 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15480 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15482 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15483 | |
| 15484 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15485 | ASSERT_TRUE(response); |
| 15486 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15487 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15488 | |
| 15489 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15490 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15491 | EXPECT_EQ("hello!", response_data); |
| 15492 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15493 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15494 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15495 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15497 | |
| 15498 | HttpRequestInfo request2; |
| 15499 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15500 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15501 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15502 | request2.traffic_annotation = |
| 15503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15504 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15505 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15506 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15508 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15509 | |
| 15510 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15511 | ASSERT_TRUE(response); |
| 15512 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15513 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15514 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15515 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15516 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15517 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15518 | } |
| 15519 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15520 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15521 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15522 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15524 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15525 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15526 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15527 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15528 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15529 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15530 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15531 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15532 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15533 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15534 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15535 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15536 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15537 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15538 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15539 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15540 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15541 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15542 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15543 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15544 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15545 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15546 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15547 | }; |
| 15548 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15549 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15550 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15551 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15552 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15553 | |
| 15554 | TestCompletionCallback callback; |
| 15555 | HttpRequestInfo request1; |
| 15556 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15557 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15558 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15559 | request1.traffic_annotation = |
| 15560 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15561 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15563 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15565 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15566 | |
| 15567 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15568 | ASSERT_TRUE(response); |
| 15569 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15570 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15571 | |
| 15572 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15573 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15574 | EXPECT_EQ("hello!", response_data); |
| 15575 | |
| 15576 | HttpRequestInfo request2; |
| 15577 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15578 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15579 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15580 | request2.traffic_annotation = |
| 15581 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15582 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15584 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15585 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15586 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15587 | |
| 15588 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15589 | ASSERT_TRUE(response); |
| 15590 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15591 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15592 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15593 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15594 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15595 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15596 | } |
| 15597 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15598 | // Regression test for https://crbug.com/546991. |
| 15599 | // The server might not be able to serve an IP pooled request, and might send a |
| 15600 | // 421 Misdirected Request response status to indicate this. |
| 15601 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15602 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15603 | // Two hosts resolve to the same IP address. |
| 15604 | const std::string ip_addr = "1.2.3.4"; |
| 15605 | IPAddress ip; |
| 15606 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15607 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15608 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15609 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15610 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15611 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15612 | |
| 15613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15614 | |
| 15615 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15616 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15617 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15618 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15619 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15620 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15621 | spdy::SpdySerializedFrame rst( |
| 15622 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15623 | MockWrite writes1[] = { |
| 15624 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15625 | CreateMockWrite(rst, 6), |
| 15626 | }; |
| 15627 | |
| 15628 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15629 | spdy::SpdySerializedFrame resp1( |
| 15630 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15631 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15632 | spdy::SpdyHeaderBlock response_headers; |
| 15633 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15634 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15635 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15636 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15637 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15638 | |
| 15639 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15640 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15641 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15642 | |
| 15643 | AddSSLSocketData(); |
| 15644 | |
| 15645 | // Retry the second request on a second connection. |
| 15646 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15647 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15648 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15649 | MockWrite writes2[] = { |
| 15650 | CreateMockWrite(req3, 0), |
| 15651 | }; |
| 15652 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15653 | spdy::SpdySerializedFrame resp3( |
| 15654 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15655 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15656 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15657 | MockRead(ASYNC, 0, 3)}; |
| 15658 | |
| 15659 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15660 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15661 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15662 | |
| 15663 | AddSSLSocketData(); |
| 15664 | |
| 15665 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15666 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15667 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15668 | EXPECT_THAT(rv, IsOk()); |
| 15669 | |
| 15670 | HttpRequestInfo request1; |
| 15671 | request1.method = "GET"; |
| 15672 | request1.url = GURL("https://www.example.org/"); |
| 15673 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15674 | request1.traffic_annotation = |
| 15675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15676 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15677 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15678 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15679 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15681 | rv = callback.WaitForResult(); |
| 15682 | EXPECT_THAT(rv, IsOk()); |
| 15683 | |
| 15684 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15685 | ASSERT_TRUE(response); |
| 15686 | ASSERT_TRUE(response->headers); |
| 15687 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15688 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15689 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15690 | std::string response_data; |
| 15691 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15692 | EXPECT_EQ("hello!", response_data); |
| 15693 | |
| 15694 | HttpRequestInfo request2; |
| 15695 | request2.method = "GET"; |
| 15696 | request2.url = GURL("https://mail.example.org/"); |
| 15697 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15698 | request2.traffic_annotation = |
| 15699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15700 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15701 | |
| 15702 | BoundTestNetLog log; |
| 15703 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15705 | rv = callback.WaitForResult(); |
| 15706 | EXPECT_THAT(rv, IsOk()); |
| 15707 | |
| 15708 | response = trans2.GetResponseInfo(); |
| 15709 | ASSERT_TRUE(response); |
| 15710 | ASSERT_TRUE(response->headers); |
| 15711 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15712 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15713 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15714 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15715 | EXPECT_EQ("hello!", response_data); |
| 15716 | |
| 15717 | TestNetLogEntry::List entries; |
| 15718 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15719 | ExpectLogContainsSomewhere( |
| 15720 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15721 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15722 | } |
| 15723 | |
| 15724 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15725 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15726 | // portions of the response. |
| 15727 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15728 | // Two hosts resolve to the same IP address. |
| 15729 | const std::string ip_addr = "1.2.3.4"; |
| 15730 | IPAddress ip; |
| 15731 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15732 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15733 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15734 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15735 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15736 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15737 | |
| 15738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15739 | |
| 15740 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15741 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15742 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15743 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15744 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15745 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15746 | spdy::SpdySerializedFrame rst( |
| 15747 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15748 | MockWrite writes1[] = { |
| 15749 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15750 | CreateMockWrite(rst, 6), |
| 15751 | }; |
| 15752 | |
| 15753 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15754 | spdy::SpdySerializedFrame resp1( |
| 15755 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15756 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15757 | spdy::SpdyHeaderBlock response_headers; |
| 15758 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15759 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15760 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15761 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15762 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15763 | |
| 15764 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15765 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15766 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15767 | |
| 15768 | AddSSLSocketData(); |
| 15769 | |
| 15770 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15771 | // Retry again. |
| 15772 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15773 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15774 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15775 | MockWrite writes2[] = { |
| 15776 | CreateMockWrite(req3, 0), |
| 15777 | }; |
| 15778 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15779 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15780 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15781 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15782 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15783 | MockRead(ASYNC, 0, 3)}; |
| 15784 | |
| 15785 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15786 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15787 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15788 | |
| 15789 | AddSSLSocketData(); |
| 15790 | |
| 15791 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15792 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15793 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15794 | EXPECT_THAT(rv, IsOk()); |
| 15795 | |
| 15796 | HttpRequestInfo request1; |
| 15797 | request1.method = "GET"; |
| 15798 | request1.url = GURL("https://www.example.org/"); |
| 15799 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15800 | request1.traffic_annotation = |
| 15801 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15802 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15803 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15804 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15805 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15807 | rv = callback.WaitForResult(); |
| 15808 | EXPECT_THAT(rv, IsOk()); |
| 15809 | |
| 15810 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15811 | ASSERT_TRUE(response); |
| 15812 | ASSERT_TRUE(response->headers); |
| 15813 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15814 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15815 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15816 | std::string response_data; |
| 15817 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15818 | EXPECT_EQ("hello!", response_data); |
| 15819 | |
| 15820 | HttpRequestInfo request2; |
| 15821 | request2.method = "GET"; |
| 15822 | request2.url = GURL("https://mail.example.org/"); |
| 15823 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15824 | request2.traffic_annotation = |
| 15825 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15826 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15827 | |
| 15828 | BoundTestNetLog log; |
| 15829 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15831 | rv = callback.WaitForResult(); |
| 15832 | EXPECT_THAT(rv, IsOk()); |
| 15833 | |
| 15834 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15835 | // caller. |
| 15836 | response = trans2.GetResponseInfo(); |
| 15837 | ASSERT_TRUE(response); |
| 15838 | ASSERT_TRUE(response->headers); |
| 15839 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15840 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15841 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15842 | EXPECT_TRUE(response->ssl_info.cert); |
| 15843 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15844 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15845 | } |
| 15846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15847 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15848 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15849 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15850 | session_deps_.host_resolver = |
| 15851 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15853 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15854 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15855 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15856 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15857 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15858 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15859 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15860 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15861 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15862 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15863 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15864 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15865 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15866 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15867 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15868 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15869 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15870 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15871 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15872 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15873 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15874 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15875 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15876 | }; |
| 15877 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15878 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15879 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15880 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15881 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15882 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15883 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15884 | HttpRequestInfo request1; |
| 15885 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15886 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15887 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15888 | request1.traffic_annotation = |
| 15889 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15890 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15892 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15894 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15895 | |
| 15896 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15897 | ASSERT_TRUE(response); |
| 15898 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15899 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15900 | |
| 15901 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15902 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15903 | EXPECT_EQ("hello!", response_data); |
| 15904 | |
| 15905 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15906 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15907 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15908 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15909 | |
| 15910 | HttpRequestInfo request2; |
| 15911 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15912 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15913 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15914 | request2.traffic_annotation = |
| 15915 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15916 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15918 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15920 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15921 | |
| 15922 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15923 | ASSERT_TRUE(response); |
| 15924 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15925 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15926 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15927 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15928 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15929 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15930 | } |
| 15931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15932 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15933 | const std::string https_url = "https://www.example.org:8080/"; |
| 15934 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15935 | |
| 15936 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15937 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15938 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15939 | |
| 15940 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15941 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15942 | }; |
| 15943 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15944 | spdy::SpdySerializedFrame resp1( |
| 15945 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15946 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15947 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15948 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15950 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15951 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15952 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15953 | |
| 15954 | // HTTP GET for the HTTP URL |
| 15955 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15956 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15957 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15958 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15959 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15960 | }; |
| 15961 | |
| 15962 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15963 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15964 | MockRead(ASYNC, 2, "hello"), |
| 15965 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15966 | }; |
| 15967 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15968 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15969 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15970 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15971 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15973 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15974 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15977 | |
| 15978 | // Start the first transaction to set up the SpdySession |
| 15979 | HttpRequestInfo request1; |
| 15980 | request1.method = "GET"; |
| 15981 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15982 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15983 | request1.traffic_annotation = |
| 15984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15985 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15986 | TestCompletionCallback callback1; |
| 15987 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15988 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15989 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15990 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15991 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15992 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15993 | |
| 15994 | // Now, start the HTTP request |
| 15995 | HttpRequestInfo request2; |
| 15996 | request2.method = "GET"; |
| 15997 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15998 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15999 | request2.traffic_annotation = |
| 16000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16001 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16002 | TestCompletionCallback callback2; |
| 16003 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16004 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16005 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16006 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16007 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16008 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16009 | } |
| 16010 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16011 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16012 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16013 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16014 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16015 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16016 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16017 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16018 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16019 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16021 | |
| 16022 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16023 | // negotiated. |
| 16024 | StaticSocketDataProvider data; |
| 16025 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16026 | |
| 16027 | // 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] | 16028 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16029 | // mocked. This way the request relies on the alternate Job. |
| 16030 | StaticSocketDataProvider data_refused; |
| 16031 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16032 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16033 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16034 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16036 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16037 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16038 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16039 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16040 | http_server_properties->SetHttp2AlternativeService( |
| 16041 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16042 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16043 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16045 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16046 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16047 | request.traffic_annotation = |
| 16048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16049 | TestCompletionCallback callback; |
| 16050 | |
| 16051 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16052 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16054 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16055 | } |
| 16056 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16057 | // 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] | 16058 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16059 | // succeeds, the request should succeed, even if the latter fails because |
| 16060 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16061 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16062 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16063 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16064 | |
| 16065 | // Negotiate HTTP/1.1 with alternative. |
| 16066 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16067 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16068 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16069 | |
| 16070 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16071 | // negotiated. |
| 16072 | StaticSocketDataProvider data; |
| 16073 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16074 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16075 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16076 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16077 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16079 | |
| 16080 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16081 | MockWrite("GET / HTTP/1.1\r\n" |
| 16082 | "Host: www.example.org\r\n" |
| 16083 | "Connection: keep-alive\r\n\r\n"), |
| 16084 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16085 | "Host: www.example.org\r\n" |
| 16086 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16087 | }; |
| 16088 | |
| 16089 | MockRead http_reads[] = { |
| 16090 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16091 | MockRead("Content-Type: text/html\r\n"), |
| 16092 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16093 | MockRead("foobar"), |
| 16094 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16095 | MockRead("Content-Type: text/html\r\n"), |
| 16096 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16097 | MockRead("another"), |
| 16098 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16099 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16100 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16101 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16102 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16103 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16104 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16105 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16106 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16107 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16108 | http_server_properties->SetHttp2AlternativeService( |
| 16109 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16110 | |
| 16111 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16112 | HttpRequestInfo request1; |
| 16113 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16114 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16115 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16116 | request1.traffic_annotation = |
| 16117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16118 | TestCompletionCallback callback1; |
| 16119 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16120 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16121 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16122 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16123 | |
| 16124 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16125 | ASSERT_TRUE(response1); |
| 16126 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16127 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16128 | |
| 16129 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16130 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16131 | EXPECT_EQ("foobar", response_data1); |
| 16132 | |
| 16133 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16134 | // for alternative service. |
| 16135 | EXPECT_TRUE( |
| 16136 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16137 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16138 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16139 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16140 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16141 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16142 | HttpRequestInfo request2; |
| 16143 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16144 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16145 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16146 | request2.traffic_annotation = |
| 16147 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16148 | TestCompletionCallback callback2; |
| 16149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16150 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16151 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16152 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16153 | |
| 16154 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16155 | ASSERT_TRUE(response2); |
| 16156 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16157 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16158 | |
| 16159 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16160 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16161 | EXPECT_EQ("another", response_data2); |
| 16162 | } |
| 16163 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16164 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16165 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16166 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16167 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16168 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16169 | HostPortPair alternative("alternative.example.org", 443); |
| 16170 | std::string origin_url = "https://origin.example.org:443"; |
| 16171 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16172 | |
| 16173 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16174 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16175 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16177 | |
| 16178 | // HTTP/1.1 data for |request1| and |request2|. |
| 16179 | MockWrite http_writes[] = { |
| 16180 | MockWrite( |
| 16181 | "GET / HTTP/1.1\r\n" |
| 16182 | "Host: alternative.example.org\r\n" |
| 16183 | "Connection: keep-alive\r\n\r\n"), |
| 16184 | MockWrite( |
| 16185 | "GET / HTTP/1.1\r\n" |
| 16186 | "Host: alternative.example.org\r\n" |
| 16187 | "Connection: keep-alive\r\n\r\n"), |
| 16188 | }; |
| 16189 | |
| 16190 | MockRead http_reads[] = { |
| 16191 | MockRead( |
| 16192 | "HTTP/1.1 200 OK\r\n" |
| 16193 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16194 | "Content-Length: 40\r\n\r\n" |
| 16195 | "first HTTP/1.1 response from alternative"), |
| 16196 | MockRead( |
| 16197 | "HTTP/1.1 200 OK\r\n" |
| 16198 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16199 | "Content-Length: 41\r\n\r\n" |
| 16200 | "second HTTP/1.1 response from alternative"), |
| 16201 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16202 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16203 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16204 | |
| 16205 | // This test documents that an alternate Job should not pool to an already |
| 16206 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16207 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16208 | StaticSocketDataProvider data_refused; |
| 16209 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16210 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16211 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16212 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16214 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16215 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16216 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16217 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16218 | http_server_properties->SetHttp2AlternativeService( |
| 16219 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16220 | |
| 16221 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16222 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16223 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16224 | request1.method = "GET"; |
| 16225 | request1.url = GURL(alternative_url); |
| 16226 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16227 | request1.traffic_annotation = |
| 16228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16229 | TestCompletionCallback callback1; |
| 16230 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16231 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16232 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16233 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16234 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16235 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16236 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16237 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16238 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16239 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16240 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16241 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16242 | |
| 16243 | // Request for origin.example.org, which has an alternative service. This |
| 16244 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16245 | // 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] | 16246 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16247 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16248 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16249 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16250 | request2.method = "GET"; |
| 16251 | request2.url = GURL(origin_url); |
| 16252 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16253 | request2.traffic_annotation = |
| 16254 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16255 | TestCompletionCallback callback2; |
| 16256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16257 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16258 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16259 | |
| 16260 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16261 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16262 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16263 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16264 | request3.method = "GET"; |
| 16265 | request3.url = GURL(alternative_url); |
| 16266 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16267 | request3.traffic_annotation = |
| 16268 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16269 | TestCompletionCallback callback3; |
| 16270 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16271 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16272 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16273 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16274 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16275 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16276 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16277 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16278 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16279 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16280 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16281 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16282 | } |
| 16283 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16284 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16285 | const std::string https_url = "https://www.example.org:8080/"; |
| 16286 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16287 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16288 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16289 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16290 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16291 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16292 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16293 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16294 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16295 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16296 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16297 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16298 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16299 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16300 | |
| 16301 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16302 | spdy::SpdyHeaderBlock req2_block; |
| 16303 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16304 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16305 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16306 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16307 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16308 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16309 | |
| 16310 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16311 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16312 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16313 | }; |
| 16314 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16315 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16316 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16317 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16318 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16319 | spdy::SpdySerializedFrame body1( |
| 16320 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16321 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16322 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16323 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16324 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16325 | spdy::SpdySerializedFrame resp2( |
| 16326 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16327 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16328 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16329 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16330 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16331 | CreateMockRead(wrapped_resp1, 4), |
| 16332 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16333 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16334 | CreateMockRead(resp2, 8), |
| 16335 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16336 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16337 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16338 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16339 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16340 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16341 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16342 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16343 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16344 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16345 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16346 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16347 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16348 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16349 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16351 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16352 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16354 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16355 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16356 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16357 | |
| 16358 | // Start the first transaction to set up the SpdySession |
| 16359 | HttpRequestInfo request1; |
| 16360 | request1.method = "GET"; |
| 16361 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16362 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16363 | request1.traffic_annotation = |
| 16364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16365 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16366 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16367 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16368 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16369 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16370 | data1.RunUntilPaused(); |
| 16371 | base::RunLoop().RunUntilIdle(); |
| 16372 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16373 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16374 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16375 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16376 | LoadTimingInfo load_timing_info1; |
| 16377 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16378 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16379 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16380 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16381 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16382 | HttpRequestInfo request2; |
| 16383 | request2.method = "GET"; |
| 16384 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16385 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16386 | request2.traffic_annotation = |
| 16387 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16388 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16389 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16390 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16391 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16392 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16393 | data1.RunUntilPaused(); |
| 16394 | base::RunLoop().RunUntilIdle(); |
| 16395 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16396 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16397 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16398 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16399 | |
| 16400 | LoadTimingInfo load_timing_info2; |
| 16401 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16402 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16403 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16404 | // HTTP requests over a SPDY session should have a different connection |
| 16405 | // socket_log_id than requests over a tunnel. |
| 16406 | 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] | 16407 | } |
| 16408 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16409 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16410 | // that we do not pool other origins that resolve to the same IP when |
| 16411 | // the certificate does not match the new origin. |
| 16412 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16413 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16414 | const std::string url1 = "http://www.example.org/"; |
| 16415 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16416 | const std::string ip_addr = "1.2.3.4"; |
| 16417 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16418 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16419 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16420 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16421 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16422 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16423 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16424 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16425 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16426 | |
| 16427 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16428 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16429 | }; |
| 16430 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16431 | spdy::SpdySerializedFrame resp1( |
| 16432 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16433 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16434 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16435 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16436 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16437 | }; |
| 16438 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16439 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16440 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16441 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16442 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16443 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16444 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16445 | |
| 16446 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16447 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16448 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16449 | |
| 16450 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16451 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16452 | }; |
| 16453 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16454 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16455 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16456 | spdy::SpdySerializedFrame body2( |
| 16457 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16458 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16459 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16460 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16461 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16462 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16463 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16464 | |
| 16465 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16466 | // all others direct. |
| 16467 | ProxyConfig proxy_config; |
| 16468 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16469 | session_deps_.proxy_resolution_service = |
| 16470 | std::make_unique<ProxyResolutionService>( |
| 16471 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16472 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16473 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16474 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16475 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16476 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16477 | // Load a valid cert. Note, that this does not need to |
| 16478 | // be valid for proxy because the MockSSLClientSocket does |
| 16479 | // not actually verify it. But SpdySession will use this |
| 16480 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16481 | ssl1.ssl_info.cert = |
| 16482 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16483 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16485 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16486 | |
| 16487 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16488 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16490 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16491 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16492 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16493 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16494 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16495 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16496 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16497 | |
| 16498 | // Start the first transaction to set up the SpdySession |
| 16499 | HttpRequestInfo request1; |
| 16500 | request1.method = "GET"; |
| 16501 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16502 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16503 | request1.traffic_annotation = |
| 16504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16505 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16506 | TestCompletionCallback callback1; |
| 16507 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16508 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16509 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16510 | data1.RunUntilPaused(); |
| 16511 | base::RunLoop().RunUntilIdle(); |
| 16512 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16513 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16514 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16515 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16516 | |
| 16517 | // Now, start the HTTP request |
| 16518 | HttpRequestInfo request2; |
| 16519 | request2.method = "GET"; |
| 16520 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16521 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16522 | request2.traffic_annotation = |
| 16523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16524 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16525 | TestCompletionCallback callback2; |
| 16526 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16527 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16528 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16529 | |
| 16530 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16531 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16532 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16533 | } |
| 16534 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16535 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16536 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16537 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16538 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16539 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16540 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16541 | |
| 16542 | MockRead reads1[] = { |
| 16543 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16544 | }; |
| 16545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16546 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16547 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16548 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16549 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16550 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16551 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16552 | }; |
| 16553 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16554 | spdy::SpdySerializedFrame resp2( |
| 16555 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16556 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16557 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16558 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16559 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16560 | }; |
| 16561 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16562 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16563 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16564 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16565 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16567 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16568 | |
| 16569 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16570 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16572 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16574 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16575 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16576 | |
| 16577 | // Start the first transaction to set up the SpdySession and verify that |
| 16578 | // connection was closed. |
| 16579 | HttpRequestInfo request1; |
| 16580 | request1.method = "GET"; |
| 16581 | request1.url = GURL(https_url); |
| 16582 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16583 | request1.traffic_annotation = |
| 16584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16585 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16586 | TestCompletionCallback callback1; |
| 16587 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16588 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16589 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16590 | |
| 16591 | // Now, start the second request and make sure it succeeds. |
| 16592 | HttpRequestInfo request2; |
| 16593 | request2.method = "GET"; |
| 16594 | request2.url = GURL(https_url); |
| 16595 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16596 | request2.traffic_annotation = |
| 16597 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16598 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16599 | TestCompletionCallback callback2; |
| 16600 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16601 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16602 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16603 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16604 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16605 | } |
| 16606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16607 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16608 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16609 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16610 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16611 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16612 | |
| 16613 | // Use two different hosts with different IPs so they don't get pooled. |
| 16614 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16615 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16617 | |
| 16618 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16619 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16620 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16621 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16624 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16625 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16626 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16627 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16628 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16629 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16630 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16631 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16632 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16633 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16634 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16635 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16636 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16637 | }; |
| 16638 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16639 | // Use a separate test instance for the separate SpdySession that will be |
| 16640 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16641 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16642 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16643 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16644 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16645 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16646 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16647 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16648 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16649 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16650 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16651 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16652 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16653 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16654 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16655 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16656 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16657 | }; |
| 16658 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16659 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16660 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16661 | |
| 16662 | MockWrite http_write[] = { |
| 16663 | MockWrite("GET / HTTP/1.1\r\n" |
| 16664 | "Host: www.a.com\r\n" |
| 16665 | "Connection: keep-alive\r\n\r\n"), |
| 16666 | }; |
| 16667 | |
| 16668 | MockRead http_read[] = { |
| 16669 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16670 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16671 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16672 | MockRead("hello!"), |
| 16673 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16674 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16675 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16676 | |
| 16677 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16678 | SpdySessionKey spdy_session_key_a( |
| 16679 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16680 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16681 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16682 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16683 | |
| 16684 | TestCompletionCallback callback; |
| 16685 | HttpRequestInfo request1; |
| 16686 | request1.method = "GET"; |
| 16687 | request1.url = GURL("https://www.a.com/"); |
| 16688 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16689 | request1.traffic_annotation = |
| 16690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16691 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16692 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16693 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16694 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16697 | |
| 16698 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16699 | ASSERT_TRUE(response); |
| 16700 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16701 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16702 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16703 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16704 | |
| 16705 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16706 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16707 | EXPECT_EQ("hello!", response_data); |
| 16708 | trans.reset(); |
| 16709 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16710 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16711 | |
| 16712 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16713 | SpdySessionKey spdy_session_key_b( |
| 16714 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16715 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16716 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16717 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16718 | HttpRequestInfo request2; |
| 16719 | request2.method = "GET"; |
| 16720 | request2.url = GURL("https://www.b.com/"); |
| 16721 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16722 | request2.traffic_annotation = |
| 16723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16724 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16725 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16726 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16727 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16729 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16730 | |
| 16731 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16732 | ASSERT_TRUE(response); |
| 16733 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16734 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16735 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16736 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16737 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16738 | EXPECT_EQ("hello!", response_data); |
| 16739 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16740 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16741 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16742 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16743 | |
| 16744 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16745 | SpdySessionKey spdy_session_key_a1( |
| 16746 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16747 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16748 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16749 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16750 | HttpRequestInfo request3; |
| 16751 | request3.method = "GET"; |
| 16752 | request3.url = GURL("http://www.a.com/"); |
| 16753 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16754 | request3.traffic_annotation = |
| 16755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16756 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16757 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16759 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16761 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16762 | |
| 16763 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16764 | ASSERT_TRUE(response); |
| 16765 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16766 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16767 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16768 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16769 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16770 | EXPECT_EQ("hello!", response_data); |
| 16771 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16772 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16773 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16774 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16775 | } |
| 16776 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16777 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16778 | HttpRequestInfo request; |
| 16779 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16780 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16781 | request.traffic_annotation = |
| 16782 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16786 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16787 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16788 | StaticSocketDataProvider data; |
| 16789 | data.set_connect_data(mock_connect); |
| 16790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16791 | |
| 16792 | TestCompletionCallback callback; |
| 16793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16794 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16796 | |
| 16797 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16798 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16799 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16800 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16801 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16802 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16803 | |
| 16804 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16805 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16806 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16807 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16808 | |
| 16809 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16810 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16811 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16812 | } |
| 16813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16814 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16815 | HttpRequestInfo request; |
| 16816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16817 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16818 | request.traffic_annotation = |
| 16819 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16820 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16822 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16823 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16824 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16825 | StaticSocketDataProvider data; |
| 16826 | data.set_connect_data(mock_connect); |
| 16827 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16828 | |
| 16829 | TestCompletionCallback callback; |
| 16830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16831 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16833 | |
| 16834 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16835 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16836 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16837 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16838 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16839 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16840 | |
| 16841 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16842 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16843 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16844 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16845 | |
| 16846 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16847 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16848 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16849 | } |
| 16850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16851 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16852 | HttpRequestInfo request; |
| 16853 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16854 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16855 | request.traffic_annotation = |
| 16856 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16860 | |
| 16861 | MockWrite data_writes[] = { |
| 16862 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16863 | }; |
| 16864 | MockRead data_reads[] = { |
| 16865 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16866 | }; |
| 16867 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16868 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16869 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16870 | |
| 16871 | TestCompletionCallback callback; |
| 16872 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16873 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16875 | |
| 16876 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16877 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16878 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16879 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16880 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16881 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16882 | } |
| 16883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16884 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16885 | HttpRequestInfo request; |
| 16886 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16887 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16888 | request.traffic_annotation = |
| 16889 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16893 | |
| 16894 | MockWrite data_writes[] = { |
| 16895 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16896 | }; |
| 16897 | MockRead data_reads[] = { |
| 16898 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16899 | }; |
| 16900 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16901 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16902 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16903 | |
| 16904 | TestCompletionCallback callback; |
| 16905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16906 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16908 | |
| 16909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16910 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16911 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16912 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16913 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16914 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16915 | } |
| 16916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16917 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16918 | HttpRequestInfo request; |
| 16919 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16920 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16921 | request.traffic_annotation = |
| 16922 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16923 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16924 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16925 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | |
| 16927 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16928 | MockWrite( |
| 16929 | "GET / HTTP/1.1\r\n" |
| 16930 | "Host: www.example.org\r\n" |
| 16931 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16932 | }; |
| 16933 | MockRead data_reads[] = { |
| 16934 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16935 | }; |
| 16936 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16937 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16939 | |
| 16940 | TestCompletionCallback callback; |
| 16941 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16942 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16944 | |
| 16945 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16946 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16947 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16948 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16949 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16950 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16951 | } |
| 16952 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16953 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16954 | HttpRequestInfo request; |
| 16955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16956 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16957 | request.traffic_annotation = |
| 16958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16961 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16962 | |
| 16963 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16964 | MockWrite( |
| 16965 | "GET / HTTP/1.1\r\n" |
| 16966 | "Host: www.example.org\r\n" |
| 16967 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16968 | }; |
| 16969 | MockRead data_reads[] = { |
| 16970 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16971 | }; |
| 16972 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16973 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16974 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16975 | |
| 16976 | TestCompletionCallback callback; |
| 16977 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16978 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16980 | |
| 16981 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16982 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16983 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16984 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16985 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16986 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16987 | } |
| 16988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16989 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16990 | HttpRequestInfo request; |
| 16991 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16992 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16993 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16994 | request.traffic_annotation = |
| 16995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16996 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16999 | |
| 17000 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17001 | MockWrite( |
| 17002 | "GET / HTTP/1.1\r\n" |
| 17003 | "Host: www.example.org\r\n" |
| 17004 | "Connection: keep-alive\r\n" |
| 17005 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17006 | }; |
| 17007 | MockRead data_reads[] = { |
| 17008 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17009 | "Content-Length: 5\r\n\r\n" |
| 17010 | "hello"), |
| 17011 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17012 | }; |
| 17013 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17014 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17015 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17016 | |
| 17017 | TestCompletionCallback callback; |
| 17018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17021 | |
| 17022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17024 | |
| 17025 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17026 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17027 | std::string foo; |
| 17028 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17029 | EXPECT_EQ("bar", foo); |
| 17030 | } |
| 17031 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17032 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17033 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17034 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17035 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17036 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17037 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17038 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17039 | |
| 17040 | // Set up SSL request. |
| 17041 | |
| 17042 | HttpRequestInfo ssl_request; |
| 17043 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17044 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17045 | ssl_request.traffic_annotation = |
| 17046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17047 | |
| 17048 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17049 | MockWrite( |
| 17050 | "GET / HTTP/1.1\r\n" |
| 17051 | "Host: www.example.org\r\n" |
| 17052 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17053 | }; |
| 17054 | MockRead ssl_reads[] = { |
| 17055 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17056 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17057 | MockRead("hello world"), |
| 17058 | MockRead(SYNCHRONOUS, OK), |
| 17059 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17060 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17061 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17062 | |
| 17063 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17065 | |
| 17066 | // Set up HTTP request. |
| 17067 | |
| 17068 | HttpRequestInfo http_request; |
| 17069 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17070 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17071 | http_request.traffic_annotation = |
| 17072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17073 | |
| 17074 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17075 | MockWrite( |
| 17076 | "GET / HTTP/1.1\r\n" |
| 17077 | "Host: www.example.org\r\n" |
| 17078 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17079 | }; |
| 17080 | MockRead http_reads[] = { |
| 17081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17082 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17083 | MockRead("falafel"), |
| 17084 | MockRead(SYNCHRONOUS, OK), |
| 17085 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17086 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17087 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17088 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17090 | |
| 17091 | // Start the SSL request. |
| 17092 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17093 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17094 | ASSERT_EQ(ERR_IO_PENDING, |
| 17095 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17096 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17097 | |
| 17098 | // Start the HTTP request. Pool should stall. |
| 17099 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17100 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17101 | ASSERT_EQ(ERR_IO_PENDING, |
| 17102 | http_trans.Start(&http_request, http_callback.callback(), |
| 17103 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17104 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17105 | |
| 17106 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17107 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17108 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17109 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17110 | EXPECT_EQ("hello world", response_data); |
| 17111 | |
| 17112 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17113 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17114 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17115 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17116 | |
| 17117 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17118 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17119 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17120 | EXPECT_EQ("falafel", response_data); |
| 17121 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17122 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17123 | } |
| 17124 | |
| 17125 | // Tests that when a SSL connection is established but there's no corresponding |
| 17126 | // request that needs it, the new socket is closed if the transport socket pool |
| 17127 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17128 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17129 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17130 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17131 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17132 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17133 | |
| 17134 | // Set up an ssl request. |
| 17135 | |
| 17136 | HttpRequestInfo ssl_request; |
| 17137 | ssl_request.method = "GET"; |
| 17138 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17139 | ssl_request.traffic_annotation = |
| 17140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17141 | |
| 17142 | // No data will be sent on the SSL socket. |
| 17143 | StaticSocketDataProvider ssl_data; |
| 17144 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17145 | |
| 17146 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17148 | |
| 17149 | // Set up HTTP request. |
| 17150 | |
| 17151 | HttpRequestInfo http_request; |
| 17152 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17153 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17154 | http_request.traffic_annotation = |
| 17155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17156 | |
| 17157 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17158 | MockWrite( |
| 17159 | "GET / HTTP/1.1\r\n" |
| 17160 | "Host: www.example.org\r\n" |
| 17161 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17162 | }; |
| 17163 | MockRead http_reads[] = { |
| 17164 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17165 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17166 | MockRead("falafel"), |
| 17167 | MockRead(SYNCHRONOUS, OK), |
| 17168 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17169 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17170 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17173 | |
| 17174 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17175 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17176 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17177 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17178 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17179 | |
| 17180 | // Start the HTTP request. Pool should stall. |
| 17181 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17182 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17183 | ASSERT_EQ(ERR_IO_PENDING, |
| 17184 | http_trans.Start(&http_request, http_callback.callback(), |
| 17185 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17186 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17187 | |
| 17188 | // The SSL connection will automatically be closed once the connection is |
| 17189 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17190 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17191 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17192 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17193 | EXPECT_EQ("falafel", response_data); |
| 17194 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17195 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17196 | } |
| 17197 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17198 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17199 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17200 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17201 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17202 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17203 | |
| 17204 | HttpRequestInfo request; |
| 17205 | request.method = "POST"; |
| 17206 | request.url = GURL("http://www.foo.com/"); |
| 17207 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17208 | request.traffic_annotation = |
| 17209 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17213 | // Send headers successfully, but get an error while sending the body. |
| 17214 | MockWrite data_writes[] = { |
| 17215 | MockWrite("POST / HTTP/1.1\r\n" |
| 17216 | "Host: www.foo.com\r\n" |
| 17217 | "Connection: keep-alive\r\n" |
| 17218 | "Content-Length: 3\r\n\r\n"), |
| 17219 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17220 | }; |
| 17221 | |
| 17222 | MockRead data_reads[] = { |
| 17223 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17224 | MockRead("hello world"), |
| 17225 | MockRead(SYNCHRONOUS, OK), |
| 17226 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17227 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17228 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17229 | |
| 17230 | TestCompletionCallback callback; |
| 17231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17232 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17234 | |
| 17235 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17238 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17239 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17240 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17241 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17242 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17243 | |
| 17244 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17245 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17247 | EXPECT_EQ("hello world", response_data); |
| 17248 | } |
| 17249 | |
| 17250 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17251 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17252 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17253 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17255 | MockWrite data_writes[] = { |
| 17256 | MockWrite("GET / HTTP/1.1\r\n" |
| 17257 | "Host: www.foo.com\r\n" |
| 17258 | "Connection: keep-alive\r\n\r\n"), |
| 17259 | MockWrite("POST / HTTP/1.1\r\n" |
| 17260 | "Host: www.foo.com\r\n" |
| 17261 | "Connection: keep-alive\r\n" |
| 17262 | "Content-Length: 3\r\n\r\n"), |
| 17263 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17264 | }; |
| 17265 | |
| 17266 | MockRead data_reads[] = { |
| 17267 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17268 | "Content-Length: 14\r\n\r\n"), |
| 17269 | MockRead("first response"), |
| 17270 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17271 | "Content-Length: 15\r\n\r\n"), |
| 17272 | MockRead("second response"), |
| 17273 | MockRead(SYNCHRONOUS, OK), |
| 17274 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17275 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17276 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17277 | |
| 17278 | TestCompletionCallback callback; |
| 17279 | HttpRequestInfo request1; |
| 17280 | request1.method = "GET"; |
| 17281 | request1.url = GURL("http://www.foo.com/"); |
| 17282 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17283 | request1.traffic_annotation = |
| 17284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17286 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17287 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17288 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17290 | |
| 17291 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17292 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17293 | |
| 17294 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17295 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17296 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17297 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17298 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17299 | |
| 17300 | std::string response_data1; |
| 17301 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17303 | EXPECT_EQ("first response", response_data1); |
| 17304 | // Delete the transaction to release the socket back into the socket pool. |
| 17305 | trans1.reset(); |
| 17306 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17307 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17308 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17309 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17310 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17311 | |
| 17312 | HttpRequestInfo request2; |
| 17313 | request2.method = "POST"; |
| 17314 | request2.url = GURL("http://www.foo.com/"); |
| 17315 | request2.upload_data_stream = &upload_data_stream; |
| 17316 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17317 | request2.traffic_annotation = |
| 17318 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17320 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17321 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17323 | |
| 17324 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17327 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17328 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17329 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17330 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17331 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17332 | |
| 17333 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17334 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17335 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17336 | EXPECT_EQ("second response", response_data2); |
| 17337 | } |
| 17338 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17339 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17340 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17341 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17342 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17343 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17344 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17345 | |
| 17346 | HttpRequestInfo request; |
| 17347 | request.method = "POST"; |
| 17348 | request.url = GURL("http://www.foo.com/"); |
| 17349 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17350 | request.traffic_annotation = |
| 17351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17355 | // Send headers successfully, but get an error while sending the body. |
| 17356 | MockWrite data_writes[] = { |
| 17357 | MockWrite("POST / HTTP/1.1\r\n" |
| 17358 | "Host: www.foo.com\r\n" |
| 17359 | "Connection: keep-alive\r\n" |
| 17360 | "Content-Length: 3\r\n\r\n" |
| 17361 | "fo"), |
| 17362 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17363 | }; |
| 17364 | |
| 17365 | MockRead data_reads[] = { |
| 17366 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17367 | MockRead("hello world"), |
| 17368 | MockRead(SYNCHRONOUS, OK), |
| 17369 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17370 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17372 | |
| 17373 | TestCompletionCallback callback; |
| 17374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17375 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17377 | |
| 17378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17381 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17382 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17384 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17385 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17386 | |
| 17387 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17388 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17390 | EXPECT_EQ("hello world", response_data); |
| 17391 | } |
| 17392 | |
| 17393 | // This tests the more common case than the previous test, where headers and |
| 17394 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17395 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17396 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17397 | |
| 17398 | HttpRequestInfo request; |
| 17399 | request.method = "POST"; |
| 17400 | request.url = GURL("http://www.foo.com/"); |
| 17401 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17402 | request.traffic_annotation = |
| 17403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17407 | // Send headers successfully, but get an error while sending the body. |
| 17408 | MockWrite data_writes[] = { |
| 17409 | MockWrite("POST / HTTP/1.1\r\n" |
| 17410 | "Host: www.foo.com\r\n" |
| 17411 | "Connection: keep-alive\r\n" |
| 17412 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17413 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17414 | }; |
| 17415 | |
| 17416 | MockRead data_reads[] = { |
| 17417 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17418 | MockRead("hello world"), |
| 17419 | MockRead(SYNCHRONOUS, OK), |
| 17420 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17421 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17423 | |
| 17424 | TestCompletionCallback callback; |
| 17425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17426 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17428 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17429 | // they can't be merged with the body in a single send. Not currently |
| 17430 | // necessary since a chunked body is never merged with headers, but this makes |
| 17431 | // the test more future proof. |
| 17432 | base::RunLoop().RunUntilIdle(); |
| 17433 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17434 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17435 | |
| 17436 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17439 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17440 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17441 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17442 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17443 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17444 | |
| 17445 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17446 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17447 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17448 | EXPECT_EQ("hello world", response_data); |
| 17449 | } |
| 17450 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17451 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17452 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17453 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17454 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17455 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17456 | |
| 17457 | HttpRequestInfo request; |
| 17458 | request.method = "POST"; |
| 17459 | request.url = GURL("http://www.foo.com/"); |
| 17460 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17461 | request.traffic_annotation = |
| 17462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17466 | |
| 17467 | MockWrite data_writes[] = { |
| 17468 | MockWrite("POST / HTTP/1.1\r\n" |
| 17469 | "Host: www.foo.com\r\n" |
| 17470 | "Connection: keep-alive\r\n" |
| 17471 | "Content-Length: 3\r\n\r\n"), |
| 17472 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17473 | }; |
| 17474 | |
| 17475 | MockRead data_reads[] = { |
| 17476 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17477 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17478 | MockRead("hello world"), |
| 17479 | MockRead(SYNCHRONOUS, OK), |
| 17480 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17481 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17482 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17483 | |
| 17484 | TestCompletionCallback callback; |
| 17485 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17486 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17488 | |
| 17489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17492 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17493 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17494 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17495 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17496 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17497 | |
| 17498 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17499 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17501 | EXPECT_EQ("hello world", response_data); |
| 17502 | } |
| 17503 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17504 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17505 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17506 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17507 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17508 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17509 | |
| 17510 | HttpRequestInfo request; |
| 17511 | request.method = "POST"; |
| 17512 | request.url = GURL("http://www.foo.com/"); |
| 17513 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17514 | request.traffic_annotation = |
| 17515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17516 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17517 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17518 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17519 | // Send headers successfully, but get an error while sending the body. |
| 17520 | MockWrite data_writes[] = { |
| 17521 | MockWrite("POST / HTTP/1.1\r\n" |
| 17522 | "Host: www.foo.com\r\n" |
| 17523 | "Connection: keep-alive\r\n" |
| 17524 | "Content-Length: 3\r\n\r\n"), |
| 17525 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17526 | }; |
| 17527 | |
| 17528 | MockRead data_reads[] = { |
| 17529 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17530 | MockRead("hello world"), |
| 17531 | MockRead(SYNCHRONOUS, OK), |
| 17532 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17533 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17535 | |
| 17536 | TestCompletionCallback callback; |
| 17537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17538 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17540 | |
| 17541 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17542 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17543 | } |
| 17544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17545 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17546 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17547 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17548 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17549 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17550 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17551 | |
| 17552 | HttpRequestInfo request; |
| 17553 | request.method = "POST"; |
| 17554 | request.url = GURL("http://www.foo.com/"); |
| 17555 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17556 | request.traffic_annotation = |
| 17557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17558 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17559 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17560 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17561 | // Send headers successfully, but get an error while sending the body. |
| 17562 | MockWrite data_writes[] = { |
| 17563 | MockWrite("POST / HTTP/1.1\r\n" |
| 17564 | "Host: www.foo.com\r\n" |
| 17565 | "Connection: keep-alive\r\n" |
| 17566 | "Content-Length: 3\r\n\r\n"), |
| 17567 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17568 | }; |
| 17569 | |
| 17570 | MockRead data_reads[] = { |
| 17571 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17572 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17573 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17574 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17575 | MockRead(SYNCHRONOUS, OK), |
| 17576 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17577 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17578 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17579 | |
| 17580 | TestCompletionCallback callback; |
| 17581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17582 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17584 | |
| 17585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17586 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17587 | } |
| 17588 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17589 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17590 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17591 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17592 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17593 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17594 | |
| 17595 | HttpRequestInfo request; |
| 17596 | request.method = "POST"; |
| 17597 | request.url = GURL("http://www.foo.com/"); |
| 17598 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17599 | request.traffic_annotation = |
| 17600 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17604 | // Send headers successfully, but get an error while sending the body. |
| 17605 | MockWrite data_writes[] = { |
| 17606 | MockWrite("POST / HTTP/1.1\r\n" |
| 17607 | "Host: www.foo.com\r\n" |
| 17608 | "Connection: keep-alive\r\n" |
| 17609 | "Content-Length: 3\r\n\r\n"), |
| 17610 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17611 | }; |
| 17612 | |
| 17613 | MockRead data_reads[] = { |
| 17614 | MockRead("HTTP 0.9 rocks!"), |
| 17615 | MockRead(SYNCHRONOUS, OK), |
| 17616 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17617 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17619 | |
| 17620 | TestCompletionCallback callback; |
| 17621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17622 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17624 | |
| 17625 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17626 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17627 | } |
| 17628 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17629 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17630 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17631 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17632 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17633 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17634 | |
| 17635 | HttpRequestInfo request; |
| 17636 | request.method = "POST"; |
| 17637 | request.url = GURL("http://www.foo.com/"); |
| 17638 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17639 | request.traffic_annotation = |
| 17640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17644 | // Send headers successfully, but get an error while sending the body. |
| 17645 | MockWrite data_writes[] = { |
| 17646 | MockWrite("POST / HTTP/1.1\r\n" |
| 17647 | "Host: www.foo.com\r\n" |
| 17648 | "Connection: keep-alive\r\n" |
| 17649 | "Content-Length: 3\r\n\r\n"), |
| 17650 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17651 | }; |
| 17652 | |
| 17653 | MockRead data_reads[] = { |
| 17654 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17655 | MockRead(SYNCHRONOUS, OK), |
| 17656 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17657 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17658 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17659 | |
| 17660 | TestCompletionCallback callback; |
| 17661 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17662 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17664 | |
| 17665 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17666 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17667 | } |
| 17668 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17669 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17670 | |
| 17671 | namespace { |
| 17672 | |
| 17673 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17674 | headers->SetHeader("Connection", "Upgrade"); |
| 17675 | headers->SetHeader("Upgrade", "websocket"); |
| 17676 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17677 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17678 | } |
| 17679 | |
| 17680 | } // namespace |
| 17681 | |
| 17682 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17683 | for (bool secure : {true, false}) { |
| 17684 | MockWrite data_writes[] = { |
| 17685 | MockWrite("GET / HTTP/1.1\r\n" |
| 17686 | "Host: www.example.org\r\n" |
| 17687 | "Connection: Upgrade\r\n" |
| 17688 | "Upgrade: websocket\r\n" |
| 17689 | "Origin: http://www.example.org\r\n" |
| 17690 | "Sec-WebSocket-Version: 13\r\n" |
| 17691 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17692 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17693 | "client_max_window_bits\r\n\r\n")}; |
| 17694 | |
| 17695 | MockRead data_reads[] = { |
| 17696 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17697 | "Upgrade: websocket\r\n" |
| 17698 | "Connection: Upgrade\r\n" |
| 17699 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17700 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17701 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17702 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17703 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17704 | if (secure) |
| 17705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17706 | |
| 17707 | HttpRequestInfo request; |
| 17708 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17709 | request.url = |
| 17710 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17711 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17712 | request.traffic_annotation = |
| 17713 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17714 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17715 | TestWebSocketHandshakeStreamCreateHelper |
| 17716 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17717 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17719 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17720 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17721 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17722 | |
| 17723 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17724 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17726 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17727 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17728 | ASSERT_TRUE(stream_request); |
| 17729 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17730 | stream_request->websocket_handshake_stream_create_helper()); |
| 17731 | |
| 17732 | rv = callback.WaitForResult(); |
| 17733 | EXPECT_THAT(rv, IsOk()); |
| 17734 | |
| 17735 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17736 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17737 | } |
| 17738 | } |
| 17739 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17740 | // Verify that proxy headers are not sent to the destination server when |
| 17741 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17742 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17743 | HttpRequestInfo request; |
| 17744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17745 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17746 | request.traffic_annotation = |
| 17747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17748 | AddWebSocketHeaders(&request.extra_headers); |
| 17749 | |
| 17750 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17751 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17752 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17753 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17754 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17756 | |
| 17757 | // Since a proxy is configured, try to establish a tunnel. |
| 17758 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17759 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17760 | "Host: www.example.org:443\r\n" |
| 17761 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17762 | |
| 17763 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17764 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17765 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17766 | "Host: www.example.org:443\r\n" |
| 17767 | "Proxy-Connection: keep-alive\r\n" |
| 17768 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17769 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17770 | MockWrite("GET / HTTP/1.1\r\n" |
| 17771 | "Host: www.example.org\r\n" |
| 17772 | "Connection: Upgrade\r\n" |
| 17773 | "Upgrade: websocket\r\n" |
| 17774 | "Origin: http://www.example.org\r\n" |
| 17775 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17776 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17777 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17778 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17779 | |
| 17780 | // The proxy responds to the connect with a 407, using a persistent |
| 17781 | // connection. |
| 17782 | MockRead data_reads[] = { |
| 17783 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17784 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17785 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17786 | "Content-Length: 0\r\n" |
| 17787 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17788 | |
| 17789 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17790 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17791 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17792 | "Upgrade: websocket\r\n" |
| 17793 | "Connection: Upgrade\r\n" |
| 17794 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17795 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17796 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17798 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17799 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17800 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17801 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17802 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17803 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17804 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17805 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17806 | &websocket_stream_create_helper); |
| 17807 | |
| 17808 | { |
| 17809 | TestCompletionCallback callback; |
| 17810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17811 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17813 | |
| 17814 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17815 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17816 | } |
| 17817 | |
| 17818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17819 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17820 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17821 | EXPECT_EQ(407, response->headers->response_code()); |
| 17822 | |
| 17823 | { |
| 17824 | TestCompletionCallback callback; |
| 17825 | |
| 17826 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17827 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17829 | |
| 17830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17831 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17832 | } |
| 17833 | |
| 17834 | response = trans->GetResponseInfo(); |
| 17835 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17836 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17837 | |
| 17838 | EXPECT_EQ(101, response->headers->response_code()); |
| 17839 | |
| 17840 | trans.reset(); |
| 17841 | session->CloseAllConnections(); |
| 17842 | } |
| 17843 | |
| 17844 | // Verify that proxy headers are not sent to the destination server when |
| 17845 | // establishing a tunnel for an insecure WebSocket connection. |
| 17846 | // This requires the authentication info to be injected into the auth cache |
| 17847 | // due to crbug.com/395064 |
| 17848 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17849 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17850 | HttpRequestInfo request; |
| 17851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17852 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17853 | request.traffic_annotation = |
| 17854 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17855 | AddWebSocketHeaders(&request.extra_headers); |
| 17856 | |
| 17857 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17858 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17859 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17860 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17863 | |
| 17864 | MockWrite data_writes[] = { |
| 17865 | // Try to establish a tunnel for the WebSocket connection, with |
| 17866 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17867 | // they cannot and will not use the same TCP/IP connection as the |
| 17868 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17869 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17870 | "Host: www.example.org:80\r\n" |
| 17871 | "Proxy-Connection: keep-alive\r\n" |
| 17872 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17873 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17874 | MockWrite("GET / HTTP/1.1\r\n" |
| 17875 | "Host: www.example.org\r\n" |
| 17876 | "Connection: Upgrade\r\n" |
| 17877 | "Upgrade: websocket\r\n" |
| 17878 | "Origin: http://www.example.org\r\n" |
| 17879 | "Sec-WebSocket-Version: 13\r\n" |
| 17880 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17881 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17882 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17883 | |
| 17884 | MockRead data_reads[] = { |
| 17885 | // HTTP CONNECT with credentials. |
| 17886 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17887 | |
| 17888 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17889 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17890 | "Upgrade: websocket\r\n" |
| 17891 | "Connection: Upgrade\r\n" |
| 17892 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17894 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17896 | |
| 17897 | session->http_auth_cache()->Add( |
| 17898 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17899 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17900 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17901 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17902 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17903 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17904 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17905 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17906 | &websocket_stream_create_helper); |
| 17907 | |
| 17908 | TestCompletionCallback callback; |
| 17909 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17910 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17912 | |
| 17913 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17914 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17915 | |
| 17916 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17917 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17918 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17919 | |
| 17920 | EXPECT_EQ(101, response->headers->response_code()); |
| 17921 | |
| 17922 | trans.reset(); |
| 17923 | session->CloseAllConnections(); |
| 17924 | } |
| 17925 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 17926 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 17927 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 17928 | for (bool secure : {true, false}) { |
| 17929 | SCOPED_TRACE(secure); |
| 17930 | session_deps_.proxy_resolution_service = |
| 17931 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17932 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17933 | session_deps_.enable_quic = true; |
| 17934 | |
| 17935 | HttpRequestInfo request; |
| 17936 | request.url = |
| 17937 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17938 | AddWebSocketHeaders(&request.extra_headers); |
| 17939 | request.traffic_annotation = |
| 17940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17941 | |
| 17942 | TestWebSocketHandshakeStreamCreateHelper |
| 17943 | websocket_handshake_stream_create_helper; |
| 17944 | |
| 17945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17946 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17947 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17948 | &websocket_handshake_stream_create_helper); |
| 17949 | |
| 17950 | TestCompletionCallback callback; |
| 17951 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17953 | |
| 17954 | rv = callback.WaitForResult(); |
| 17955 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17956 | } |
| 17957 | } |
| 17958 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17959 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17961 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17962 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17963 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17964 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17965 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17966 | |
| 17967 | HttpRequestInfo request; |
| 17968 | request.method = "POST"; |
| 17969 | request.url = GURL("http://www.foo.com/"); |
| 17970 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17971 | request.traffic_annotation = |
| 17972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17973 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17975 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17976 | MockWrite data_writes[] = { |
| 17977 | MockWrite("POST / HTTP/1.1\r\n" |
| 17978 | "Host: www.foo.com\r\n" |
| 17979 | "Connection: keep-alive\r\n" |
| 17980 | "Content-Length: 3\r\n\r\n"), |
| 17981 | MockWrite("foo"), |
| 17982 | }; |
| 17983 | |
| 17984 | MockRead data_reads[] = { |
| 17985 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17986 | MockRead(SYNCHRONOUS, OK), |
| 17987 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17988 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17990 | |
| 17991 | TestCompletionCallback callback; |
| 17992 | |
| 17993 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17994 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17995 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17996 | |
| 17997 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17998 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17999 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18000 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18001 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18002 | } |
| 18003 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18004 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18005 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18006 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18007 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18008 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18009 | |
| 18010 | HttpRequestInfo request; |
| 18011 | request.method = "POST"; |
| 18012 | request.url = GURL("http://www.foo.com/"); |
| 18013 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18014 | request.traffic_annotation = |
| 18015 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18019 | MockWrite data_writes[] = { |
| 18020 | MockWrite("POST / HTTP/1.1\r\n" |
| 18021 | "Host: www.foo.com\r\n" |
| 18022 | "Connection: keep-alive\r\n" |
| 18023 | "Content-Length: 3\r\n\r\n"), |
| 18024 | MockWrite("foo"), |
| 18025 | }; |
| 18026 | |
| 18027 | MockRead data_reads[] = { |
| 18028 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18029 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18030 | MockRead(SYNCHRONOUS, OK), |
| 18031 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18032 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18033 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18034 | |
| 18035 | TestCompletionCallback callback; |
| 18036 | |
| 18037 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18038 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18039 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18040 | |
| 18041 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18042 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18043 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18044 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18045 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18046 | } |
| 18047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18048 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18049 | ChunkedUploadDataStream upload_data_stream(0); |
| 18050 | |
| 18051 | HttpRequestInfo request; |
| 18052 | request.method = "POST"; |
| 18053 | request.url = GURL("http://www.foo.com/"); |
| 18054 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18055 | request.traffic_annotation = |
| 18056 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18058 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18059 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18060 | // Send headers successfully, but get an error while sending the body. |
| 18061 | MockWrite data_writes[] = { |
| 18062 | MockWrite("POST / HTTP/1.1\r\n" |
| 18063 | "Host: www.foo.com\r\n" |
| 18064 | "Connection: keep-alive\r\n" |
| 18065 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18066 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18067 | }; |
| 18068 | |
| 18069 | MockRead data_reads[] = { |
| 18070 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18071 | MockRead(SYNCHRONOUS, OK), |
| 18072 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18073 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18075 | |
| 18076 | TestCompletionCallback callback; |
| 18077 | |
| 18078 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18079 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18080 | |
| 18081 | base::RunLoop().RunUntilIdle(); |
| 18082 | upload_data_stream.AppendData("f", 1, false); |
| 18083 | |
| 18084 | base::RunLoop().RunUntilIdle(); |
| 18085 | upload_data_stream.AppendData("oo", 2, true); |
| 18086 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18087 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18088 | |
| 18089 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18090 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18091 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18092 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18093 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18094 | } |
| 18095 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18096 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18097 | const std::string& accept_encoding, |
| 18098 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18099 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18100 | bool should_match) { |
| 18101 | HttpRequestInfo request; |
| 18102 | request.method = "GET"; |
| 18103 | request.url = GURL("http://www.foo.com/"); |
| 18104 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18105 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18106 | request.traffic_annotation = |
| 18107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18108 | |
| 18109 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18110 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18111 | // Send headers successfully, but get an error while sending the body. |
| 18112 | MockWrite data_writes[] = { |
| 18113 | MockWrite("GET / HTTP/1.1\r\n" |
| 18114 | "Host: www.foo.com\r\n" |
| 18115 | "Connection: keep-alive\r\n" |
| 18116 | "Accept-Encoding: "), |
| 18117 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18118 | }; |
| 18119 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18120 | std::string response_code = "200 OK"; |
| 18121 | std::string extra; |
| 18122 | if (!location.empty()) { |
| 18123 | response_code = "301 Redirect\r\nLocation: "; |
| 18124 | response_code.append(location); |
| 18125 | } |
| 18126 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18127 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18128 | MockRead("HTTP/1.0 "), |
| 18129 | MockRead(response_code.data()), |
| 18130 | MockRead("\r\nContent-Encoding: "), |
| 18131 | MockRead(content_encoding.data()), |
| 18132 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18133 | MockRead(SYNCHRONOUS, OK), |
| 18134 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18135 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18136 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18137 | |
| 18138 | TestCompletionCallback callback; |
| 18139 | |
| 18140 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18142 | |
| 18143 | rv = callback.WaitForResult(); |
| 18144 | if (should_match) { |
| 18145 | EXPECT_THAT(rv, IsOk()); |
| 18146 | } else { |
| 18147 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18148 | } |
| 18149 | } |
| 18150 | |
| 18151 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18152 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18153 | } |
| 18154 | |
| 18155 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18156 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18157 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18158 | } |
| 18159 | |
| 18160 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18161 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18162 | "", false); |
| 18163 | } |
| 18164 | |
| 18165 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18166 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18167 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18168 | } |
| 18169 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18170 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18171 | ProxyConfig proxy_config; |
| 18172 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18173 | proxy_config.set_pac_mandatory(true); |
| 18174 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18175 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18176 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18177 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18178 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18179 | |
| 18180 | HttpRequestInfo request; |
| 18181 | request.method = "GET"; |
| 18182 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18183 | request.traffic_annotation = |
| 18184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18185 | |
| 18186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18187 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18188 | |
| 18189 | TestCompletionCallback callback; |
| 18190 | |
| 18191 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18193 | EXPECT_THAT(callback.WaitForResult(), |
| 18194 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18195 | } |
| 18196 | |
| 18197 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18198 | ProxyConfig proxy_config; |
| 18199 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18200 | proxy_config.set_pac_mandatory(true); |
| 18201 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18202 | new MockAsyncProxyResolverFactory(false); |
| 18203 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18204 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18205 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18206 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18207 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18208 | HttpRequestInfo request; |
| 18209 | request.method = "GET"; |
| 18210 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18211 | request.traffic_annotation = |
| 18212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18213 | |
| 18214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18215 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18216 | |
| 18217 | TestCompletionCallback callback; |
| 18218 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18220 | |
| 18221 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18222 | ERR_FAILED, &resolver); |
| 18223 | EXPECT_THAT(callback.WaitForResult(), |
| 18224 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18225 | } |
| 18226 | |
| 18227 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18228 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18229 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18230 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18231 | session_deps_.enable_quic = false; |
| 18232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18233 | |
| 18234 | HttpRequestInfo request; |
| 18235 | request.method = "GET"; |
| 18236 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 18237 | request.traffic_annotation = |
| 18238 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18239 | |
| 18240 | TestCompletionCallback callback; |
| 18241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18242 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18244 | |
| 18245 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18246 | } |
| 18247 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18248 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18249 | // Reporting tests |
| 18250 | |
| 18251 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18252 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18253 | protected: |
| 18254 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18255 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18256 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18257 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18258 | test_reporting_context_ = test_reporting_context.get(); |
| 18259 | session_deps_.reporting_service = |
| 18260 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18261 | } |
| 18262 | |
| 18263 | TestReportingContext* reporting_context() const { |
| 18264 | return test_reporting_context_; |
| 18265 | } |
| 18266 | |
| 18267 | void clear_reporting_service() { |
| 18268 | session_deps_.reporting_service.reset(); |
| 18269 | test_reporting_context_ = nullptr; |
| 18270 | } |
| 18271 | |
| 18272 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18273 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18274 | HttpRequestInfo request; |
| 18275 | request.method = "GET"; |
| 18276 | request.url = GURL(url_); |
| 18277 | request.traffic_annotation = |
| 18278 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18279 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18280 | MockWrite data_writes[] = { |
| 18281 | MockWrite("GET / HTTP/1.1\r\n" |
| 18282 | "Host: www.example.org\r\n" |
| 18283 | "Connection: keep-alive\r\n\r\n"), |
| 18284 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18285 | MockRead data_reads[] = { |
| 18286 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18287 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18288 | "\"endpoints\": [{\"url\": " |
| 18289 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18290 | MockRead("\r\n"), |
| 18291 | MockRead("hello world"), |
| 18292 | MockRead(SYNCHRONOUS, OK), |
| 18293 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18294 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18295 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18296 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18297 | |
| 18298 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18299 | if (request.url.SchemeIsCryptographic()) { |
| 18300 | ssl.ssl_info.cert = |
| 18301 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18302 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18303 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18304 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18305 | } |
| 18306 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18307 | TestCompletionCallback callback; |
| 18308 | auto session = CreateSession(&session_deps_); |
| 18309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18310 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18311 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18312 | } |
| 18313 | |
| 18314 | protected: |
| 18315 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18316 | |
| 18317 | private: |
| 18318 | TestReportingContext* test_reporting_context_; |
| 18319 | }; |
| 18320 | |
| 18321 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18322 | DontProcessReportToHeaderNoService) { |
| 18323 | base::HistogramTester histograms; |
| 18324 | clear_reporting_service(); |
| 18325 | RequestPolicy(); |
| 18326 | histograms.ExpectBucketCount( |
| 18327 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18328 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18329 | } |
| 18330 | |
| 18331 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18332 | base::HistogramTester histograms; |
| 18333 | url_ = "http://www.example.org/"; |
| 18334 | RequestPolicy(); |
| 18335 | histograms.ExpectBucketCount( |
| 18336 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18337 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18338 | } |
| 18339 | |
| 18340 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18341 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18342 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
| 18343 | const ReportingClient endpoint = |
| 18344 | reporting_context()->cache()->GetEndpointForTesting( |
| 18345 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18346 | GURL("https://www.example.org/upload/")); |
| 18347 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18348 | } |
| 18349 | |
| 18350 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18351 | DontProcessReportToHeaderInvalidHttps) { |
| 18352 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18353 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18354 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18355 | histograms.ExpectBucketCount( |
| 18356 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18357 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18358 | } |
| 18359 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18360 | |
| 18361 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18362 | // Network Error Logging tests |
| 18363 | |
| 18364 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18365 | namespace { |
| 18366 | |
| 18367 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18368 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18369 | |
| 18370 | } // namespace |
| 18371 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18372 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18373 | : public HttpNetworkTransactionTest { |
| 18374 | protected: |
| 18375 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18376 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18377 | auto network_error_logging_service = |
| 18378 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18379 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18380 | session_deps_.network_error_logging_service = |
| 18381 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18382 | |
| 18383 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18384 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18385 | |
| 18386 | request_.method = "GET"; |
| 18387 | request_.url = GURL(url_); |
| 18388 | request_.extra_headers = extra_headers_; |
| 18389 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18390 | request_.traffic_annotation = |
| 18391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18392 | } |
| 18393 | |
| 18394 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18395 | return test_network_error_logging_service_; |
| 18396 | } |
| 18397 | |
| 18398 | void clear_network_error_logging_service() { |
| 18399 | session_deps_.network_error_logging_service.reset(); |
| 18400 | test_network_error_logging_service_ = nullptr; |
| 18401 | } |
| 18402 | |
| 18403 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18404 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18405 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18406 | MockWrite data_writes[] = { |
| 18407 | MockWrite("GET / HTTP/1.1\r\n" |
| 18408 | "Host: www.example.org\r\n" |
| 18409 | "Connection: keep-alive\r\n"), |
| 18410 | MockWrite(ASYNC, extra_header_string.data(), |
| 18411 | extra_header_string.size()), |
| 18412 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18413 | MockRead data_reads[] = { |
| 18414 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18415 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18416 | MockRead("\r\n"), |
| 18417 | MockRead("hello world"), |
| 18418 | MockRead(SYNCHRONOUS, OK), |
| 18419 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18420 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18421 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18422 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18423 | |
| 18424 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18425 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18426 | ssl.ssl_info.cert = |
| 18427 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18428 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18429 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18431 | } |
| 18432 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18433 | TestCompletionCallback callback; |
| 18434 | auto session = CreateSession(&session_deps_); |
| 18435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18436 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18437 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18438 | |
| 18439 | std::string response_data; |
| 18440 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18441 | EXPECT_EQ("hello world", response_data); |
| 18442 | } |
| 18443 | |
| 18444 | void CheckReport(size_t index, |
| 18445 | int status_code, |
| 18446 | int error_type, |
| 18447 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18448 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18449 | |
| 18450 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18451 | network_error_logging_service()->errors()[index]; |
| 18452 | EXPECT_EQ(url_, error.uri); |
| 18453 | EXPECT_EQ(kReferrer, error.referrer); |
| 18454 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18455 | EXPECT_EQ(server_ip, error.server_ip); |
| 18456 | EXPECT_EQ("http/1.1", error.protocol); |
| 18457 | EXPECT_EQ("GET", error.method); |
| 18458 | EXPECT_EQ(status_code, error.status_code); |
| 18459 | EXPECT_EQ(error_type, error.type); |
| 18460 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18461 | } |
| 18462 | |
| 18463 | protected: |
| 18464 | std::string url_ = "https://www.example.org/"; |
| 18465 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18466 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18467 | HttpRequestHeaders extra_headers_; |
| 18468 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18469 | |
| 18470 | private: |
| 18471 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18472 | }; |
| 18473 | |
| 18474 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18475 | DontProcessNelHeaderNoService) { |
| 18476 | base::HistogramTester histograms; |
| 18477 | clear_network_error_logging_service(); |
| 18478 | RequestPolicy(); |
| 18479 | histograms.ExpectBucketCount( |
| 18480 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18481 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18482 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18483 | 1); |
| 18484 | } |
| 18485 | |
| 18486 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18487 | DontProcessNelHeaderHttp) { |
| 18488 | base::HistogramTester histograms; |
| 18489 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18490 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18491 | RequestPolicy(); |
| 18492 | histograms.ExpectBucketCount( |
| 18493 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18494 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18495 | } |
| 18496 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18497 | // Don't set NEL policies received on a proxied connection. |
| 18498 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18499 | DontProcessNelHeaderProxy) { |
| 18500 | session_deps_.proxy_resolution_service = |
| 18501 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18502 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18503 | BoundTestNetLog log; |
| 18504 | session_deps_.net_log = log.bound().net_log(); |
| 18505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18506 | |
| 18507 | HttpRequestInfo request; |
| 18508 | request.method = "GET"; |
| 18509 | request.url = GURL("https://www.example.org/"); |
| 18510 | request.traffic_annotation = |
| 18511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18512 | |
| 18513 | // Since we have proxy, should try to establish tunnel. |
| 18514 | MockWrite data_writes1[] = { |
| 18515 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18516 | "Host: www.example.org:443\r\n" |
| 18517 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18518 | |
| 18519 | MockWrite("GET / HTTP/1.1\r\n" |
| 18520 | "Host: www.example.org\r\n" |
| 18521 | "Connection: keep-alive\r\n\r\n"), |
| 18522 | }; |
| 18523 | |
| 18524 | MockRead data_reads1[] = { |
| 18525 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18526 | |
| 18527 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18528 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18530 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18531 | MockRead(SYNCHRONOUS, OK), |
| 18532 | }; |
| 18533 | |
| 18534 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18535 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18536 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18537 | ssl.ssl_info.cert = |
| 18538 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18539 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18540 | ssl.ssl_info.cert_status = 0; |
| 18541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18542 | |
| 18543 | TestCompletionCallback callback1; |
| 18544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18545 | |
| 18546 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18548 | |
| 18549 | rv = callback1.WaitForResult(); |
| 18550 | EXPECT_THAT(rv, IsOk()); |
| 18551 | |
| 18552 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18553 | ASSERT_TRUE(response); |
| 18554 | EXPECT_EQ(200, response->headers->response_code()); |
| 18555 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18556 | |
| 18557 | // No NEL header was set. |
| 18558 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18559 | } |
| 18560 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18561 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18562 | RequestPolicy(); |
| 18563 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18564 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18565 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18566 | header.origin); |
| 18567 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18568 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18569 | } |
| 18570 | |
| 18571 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18572 | DontProcessNelHeaderInvalidHttps) { |
| 18573 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18574 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18575 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18576 | histograms.ExpectBucketCount( |
| 18577 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18578 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18579 | 1); |
| 18580 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18581 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18582 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18583 | RequestPolicy(); |
| 18584 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18585 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18586 | } |
| 18587 | |
| 18588 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18589 | CreateReportErrorAfterStart) { |
| 18590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18591 | auto trans = |
| 18592 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18593 | |
| 18594 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18595 | StaticSocketDataProvider data; |
| 18596 | data.set_connect_data(mock_connect); |
| 18597 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18598 | |
| 18599 | TestCompletionCallback callback; |
| 18600 | |
| 18601 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18602 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18603 | |
| 18604 | trans.reset(); |
| 18605 | |
| 18606 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18607 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18608 | IPAddress() /* server_ip */); |
| 18609 | } |
| 18610 | |
| 18611 | // Same as above except the error is ASYNC |
| 18612 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18613 | CreateReportErrorAfterStartAsync) { |
| 18614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18615 | auto trans = |
| 18616 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18617 | |
| 18618 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18619 | StaticSocketDataProvider data; |
| 18620 | data.set_connect_data(mock_connect); |
| 18621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18622 | |
| 18623 | TestCompletionCallback callback; |
| 18624 | |
| 18625 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18626 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18627 | |
| 18628 | trans.reset(); |
| 18629 | |
| 18630 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18631 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18632 | IPAddress() /* server_ip */); |
| 18633 | } |
| 18634 | |
| 18635 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18636 | CreateReportReadBodyError) { |
| 18637 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18638 | MockWrite data_writes[] = { |
| 18639 | MockWrite("GET / HTTP/1.1\r\n" |
| 18640 | "Host: www.example.org\r\n" |
| 18641 | "Connection: keep-alive\r\n"), |
| 18642 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18643 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18644 | MockRead data_reads[] = { |
| 18645 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18646 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18647 | MockRead("hello world"), |
| 18648 | MockRead(SYNCHRONOUS, OK), |
| 18649 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18650 | |
| 18651 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18652 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18653 | |
| 18654 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18656 | |
| 18657 | // Log start time |
| 18658 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18659 | |
| 18660 | TestCompletionCallback callback; |
| 18661 | auto session = CreateSession(&session_deps_); |
| 18662 | auto trans = |
| 18663 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18664 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18665 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18666 | |
| 18667 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18668 | ASSERT_TRUE(response); |
| 18669 | |
| 18670 | EXPECT_TRUE(response->headers); |
| 18671 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18672 | |
| 18673 | std::string response_data; |
| 18674 | rv = ReadTransaction(trans.get(), &response_data); |
| 18675 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18676 | |
| 18677 | trans.reset(); |
| 18678 | |
| 18679 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18680 | |
| 18681 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18682 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18683 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18684 | network_error_logging_service()->errors()[0]; |
| 18685 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18686 | } |
| 18687 | |
| 18688 | // Same as above except the final read is ASYNC. |
| 18689 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18690 | CreateReportReadBodyErrorAsync) { |
| 18691 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18692 | MockWrite data_writes[] = { |
| 18693 | MockWrite("GET / HTTP/1.1\r\n" |
| 18694 | "Host: www.example.org\r\n" |
| 18695 | "Connection: keep-alive\r\n"), |
| 18696 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18697 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18698 | MockRead data_reads[] = { |
| 18699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18700 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18701 | MockRead("hello world"), |
| 18702 | MockRead(ASYNC, OK), |
| 18703 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18704 | |
| 18705 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18706 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18707 | |
| 18708 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18709 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18710 | |
| 18711 | // Log start time |
| 18712 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18713 | |
| 18714 | TestCompletionCallback callback; |
| 18715 | auto session = CreateSession(&session_deps_); |
| 18716 | auto trans = |
| 18717 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18718 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18719 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18720 | |
| 18721 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18722 | ASSERT_TRUE(response); |
| 18723 | |
| 18724 | EXPECT_TRUE(response->headers); |
| 18725 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18726 | |
| 18727 | std::string response_data; |
| 18728 | rv = ReadTransaction(trans.get(), &response_data); |
| 18729 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18730 | |
| 18731 | trans.reset(); |
| 18732 | |
| 18733 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18734 | |
| 18735 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18736 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18737 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18738 | network_error_logging_service()->errors()[0]; |
| 18739 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18740 | } |
| 18741 | |
| 18742 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18743 | CreateReportRestartWithAuth) { |
| 18744 | std::string extra_header_string = extra_headers_.ToString(); |
| 18745 | static const base::TimeDelta kSleepDuration = |
| 18746 | base::TimeDelta::FromMilliseconds(10); |
| 18747 | |
| 18748 | MockWrite data_writes1[] = { |
| 18749 | MockWrite("GET / HTTP/1.1\r\n" |
| 18750 | "Host: www.example.org\r\n" |
| 18751 | "Connection: keep-alive\r\n"), |
| 18752 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18753 | }; |
| 18754 | |
| 18755 | MockRead data_reads1[] = { |
| 18756 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18757 | // Give a couple authenticate options (only the middle one is actually |
| 18758 | // supported). |
| 18759 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18760 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18761 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18762 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18763 | // Large content-length -- won't matter, as connection will be reset. |
| 18764 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18765 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18766 | }; |
| 18767 | |
| 18768 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18769 | // be issuing -- the final header line contains the credentials. |
| 18770 | MockWrite data_writes2[] = { |
| 18771 | MockWrite("GET / HTTP/1.1\r\n" |
| 18772 | "Host: www.example.org\r\n" |
| 18773 | "Connection: keep-alive\r\n" |
| 18774 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18775 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18776 | }; |
| 18777 | |
| 18778 | // Lastly, the server responds with the actual content. |
| 18779 | MockRead data_reads2[] = { |
| 18780 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18781 | MockRead("hello world"), |
| 18782 | MockRead(SYNCHRONOUS, OK), |
| 18783 | }; |
| 18784 | |
| 18785 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18786 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18787 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18788 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18789 | |
| 18790 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18792 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18794 | |
| 18795 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18796 | base::TimeTicks restart_time; |
| 18797 | |
| 18798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18799 | auto trans = |
| 18800 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18801 | |
| 18802 | TestCompletionCallback callback1; |
| 18803 | |
| 18804 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18805 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18806 | |
| 18807 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18808 | |
| 18809 | TestCompletionCallback callback2; |
| 18810 | |
| 18811 | // Wait 10 ms then restart with auth |
| 18812 | FastForwardBy(kSleepDuration); |
| 18813 | restart_time = base::TimeTicks::Now(); |
| 18814 | rv = |
| 18815 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18816 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18817 | |
| 18818 | std::string response_data; |
| 18819 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18820 | EXPECT_EQ("hello world", response_data); |
| 18821 | |
| 18822 | trans.reset(); |
| 18823 | |
| 18824 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18825 | // retry. Note that we don't report the error draining the body, as the first |
| 18826 | // request already generated a report for the auth challenge. |
| 18827 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18828 | |
| 18829 | // Check error report contents |
| 18830 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18831 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18832 | |
| 18833 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18834 | network_error_logging_service()->errors()[0]; |
| 18835 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18836 | network_error_logging_service()->errors()[1]; |
| 18837 | |
| 18838 | // Sanity-check elapsed time values |
| 18839 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18840 | // Check that the start time is refreshed when restarting with auth. |
| 18841 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18842 | } |
| 18843 | |
| 18844 | // Same as above, except draining the body before restarting fails |
| 18845 | // asynchronously. |
| 18846 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18847 | CreateReportRestartWithAuthAsync) { |
| 18848 | std::string extra_header_string = extra_headers_.ToString(); |
| 18849 | static const base::TimeDelta kSleepDuration = |
| 18850 | base::TimeDelta::FromMilliseconds(10); |
| 18851 | |
| 18852 | MockWrite data_writes1[] = { |
| 18853 | MockWrite("GET / HTTP/1.1\r\n" |
| 18854 | "Host: www.example.org\r\n" |
| 18855 | "Connection: keep-alive\r\n"), |
| 18856 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18857 | }; |
| 18858 | |
| 18859 | MockRead data_reads1[] = { |
| 18860 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18861 | // Give a couple authenticate options (only the middle one is actually |
| 18862 | // supported). |
| 18863 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18864 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18865 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18866 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18867 | // Large content-length -- won't matter, as connection will be reset. |
| 18868 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18869 | MockRead(ASYNC, ERR_FAILED), |
| 18870 | }; |
| 18871 | |
| 18872 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18873 | // be issuing -- the final header line contains the credentials. |
| 18874 | MockWrite data_writes2[] = { |
| 18875 | MockWrite("GET / HTTP/1.1\r\n" |
| 18876 | "Host: www.example.org\r\n" |
| 18877 | "Connection: keep-alive\r\n" |
| 18878 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18879 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18880 | }; |
| 18881 | |
| 18882 | // Lastly, the server responds with the actual content. |
| 18883 | MockRead data_reads2[] = { |
| 18884 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18885 | MockRead("hello world"), |
| 18886 | MockRead(SYNCHRONOUS, OK), |
| 18887 | }; |
| 18888 | |
| 18889 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18890 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18891 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18892 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18893 | |
| 18894 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18895 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18896 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18898 | |
| 18899 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18900 | base::TimeTicks restart_time; |
| 18901 | |
| 18902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18903 | auto trans = |
| 18904 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18905 | |
| 18906 | TestCompletionCallback callback1; |
| 18907 | |
| 18908 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18909 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18910 | |
| 18911 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18912 | |
| 18913 | TestCompletionCallback callback2; |
| 18914 | |
| 18915 | // Wait 10 ms then restart with auth |
| 18916 | FastForwardBy(kSleepDuration); |
| 18917 | restart_time = base::TimeTicks::Now(); |
| 18918 | rv = |
| 18919 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18920 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18921 | |
| 18922 | std::string response_data; |
| 18923 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18924 | EXPECT_EQ("hello world", response_data); |
| 18925 | |
| 18926 | trans.reset(); |
| 18927 | |
| 18928 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18929 | // retry. Note that we don't report the error draining the body, as the first |
| 18930 | // request already generated a report for the auth challenge. |
| 18931 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18932 | |
| 18933 | // Check error report contents |
| 18934 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18935 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18936 | |
| 18937 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18938 | network_error_logging_service()->errors()[0]; |
| 18939 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18940 | network_error_logging_service()->errors()[1]; |
| 18941 | |
| 18942 | // Sanity-check elapsed time values |
| 18943 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18944 | // Check that the start time is refreshed when restarting with auth. |
| 18945 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18946 | } |
| 18947 | |
| 18948 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18949 | CreateReportRetryKeepAliveConnectionReset) { |
| 18950 | std::string extra_header_string = extra_headers_.ToString(); |
| 18951 | MockWrite data_writes1[] = { |
| 18952 | MockWrite("GET / HTTP/1.1\r\n" |
| 18953 | "Host: www.example.org\r\n" |
| 18954 | "Connection: keep-alive\r\n"), |
| 18955 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18956 | MockWrite("GET / HTTP/1.1\r\n" |
| 18957 | "Host: www.example.org\r\n" |
| 18958 | "Connection: keep-alive\r\n"), |
| 18959 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18960 | }; |
| 18961 | |
| 18962 | MockRead data_reads1[] = { |
| 18963 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18964 | MockRead("hello"), |
| 18965 | // Connection is reset |
| 18966 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18967 | }; |
| 18968 | |
| 18969 | // Successful retry |
| 18970 | MockRead data_reads2[] = { |
| 18971 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18972 | MockRead("world"), |
| 18973 | MockRead(ASYNC, OK), |
| 18974 | }; |
| 18975 | |
| 18976 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18977 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18978 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18979 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18980 | |
| 18981 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18983 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18985 | |
| 18986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18987 | auto trans1 = |
| 18988 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18989 | |
| 18990 | TestCompletionCallback callback1; |
| 18991 | |
| 18992 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18993 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18994 | |
| 18995 | std::string response_data; |
| 18996 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18997 | EXPECT_EQ("hello", response_data); |
| 18998 | |
| 18999 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19000 | |
| 19001 | auto trans2 = |
| 19002 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19003 | |
| 19004 | TestCompletionCallback callback2; |
| 19005 | |
| 19006 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19007 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19008 | |
| 19009 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19010 | EXPECT_EQ("world", response_data); |
| 19011 | |
| 19012 | trans1.reset(); |
| 19013 | trans2.reset(); |
| 19014 | |
| 19015 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19016 | // the second request, then an OK report from the successful retry. |
| 19017 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19018 | |
| 19019 | // Check error report contents |
| 19020 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19021 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19022 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19023 | } |
| 19024 | |
| 19025 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19026 | CreateReportRetryKeepAlive408) { |
| 19027 | std::string extra_header_string = extra_headers_.ToString(); |
| 19028 | MockWrite data_writes1[] = { |
| 19029 | MockWrite("GET / HTTP/1.1\r\n" |
| 19030 | "Host: www.example.org\r\n" |
| 19031 | "Connection: keep-alive\r\n"), |
| 19032 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19033 | MockWrite("GET / HTTP/1.1\r\n" |
| 19034 | "Host: www.example.org\r\n" |
| 19035 | "Connection: keep-alive\r\n"), |
| 19036 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19037 | }; |
| 19038 | |
| 19039 | MockRead data_reads1[] = { |
| 19040 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19041 | MockRead("hello"), |
| 19042 | // 408 Request Timeout |
| 19043 | MockRead(SYNCHRONOUS, |
| 19044 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19045 | "Connection: Keep-Alive\r\n" |
| 19046 | "Content-Length: 6\r\n\r\n" |
| 19047 | "Pickle"), |
| 19048 | }; |
| 19049 | |
| 19050 | // Successful retry |
| 19051 | MockRead data_reads2[] = { |
| 19052 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19053 | MockRead("world"), |
| 19054 | MockRead(ASYNC, OK), |
| 19055 | }; |
| 19056 | |
| 19057 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19058 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19060 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19061 | |
| 19062 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19064 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19066 | |
| 19067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19068 | auto trans1 = |
| 19069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19070 | |
| 19071 | TestCompletionCallback callback1; |
| 19072 | |
| 19073 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19074 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19075 | |
| 19076 | std::string response_data; |
| 19077 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19078 | EXPECT_EQ("hello", response_data); |
| 19079 | |
| 19080 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19081 | |
| 19082 | auto trans2 = |
| 19083 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19084 | |
| 19085 | TestCompletionCallback callback2; |
| 19086 | |
| 19087 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19088 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19089 | |
| 19090 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19091 | EXPECT_EQ("world", response_data); |
| 19092 | |
| 19093 | trans1.reset(); |
| 19094 | trans2.reset(); |
| 19095 | |
| 19096 | // One 200 report from first request, then a 408 report from |
| 19097 | // the second request, then a 200 report from the successful retry. |
| 19098 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19099 | |
| 19100 | // Check error report contents |
| 19101 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19102 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19103 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19104 | } |
| 19105 | |
| 19106 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19107 | CreateReportRetry421WithoutConnectionPooling) { |
| 19108 | // Two hosts resolve to the same IP address. |
| 19109 | const std::string ip_addr = "1.2.3.4"; |
| 19110 | IPAddress ip; |
| 19111 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19112 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19113 | |
| 19114 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19115 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19116 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19117 | |
| 19118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19119 | |
| 19120 | // Two requests on the first connection. |
| 19121 | spdy::SpdySerializedFrame req1( |
| 19122 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19123 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19124 | spdy::SpdySerializedFrame req2( |
| 19125 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19126 | spdy::SpdySerializedFrame rst( |
| 19127 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19128 | MockWrite writes1[] = { |
| 19129 | CreateMockWrite(req1, 0), |
| 19130 | CreateMockWrite(req2, 3), |
| 19131 | CreateMockWrite(rst, 6), |
| 19132 | }; |
| 19133 | |
| 19134 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19135 | spdy::SpdySerializedFrame resp1( |
| 19136 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19137 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19138 | spdy::SpdyHeaderBlock response_headers; |
| 19139 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19140 | spdy::SpdySerializedFrame resp2( |
| 19141 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19142 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19143 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19144 | |
| 19145 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19146 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19147 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19148 | |
| 19149 | AddSSLSocketData(); |
| 19150 | |
| 19151 | // Retry the second request on a second connection. |
| 19152 | SpdyTestUtil spdy_util2; |
| 19153 | spdy::SpdySerializedFrame req3( |
| 19154 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19155 | MockWrite writes2[] = { |
| 19156 | CreateMockWrite(req3, 0), |
| 19157 | }; |
| 19158 | |
| 19159 | spdy::SpdySerializedFrame resp3( |
| 19160 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19161 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19162 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19163 | MockRead(ASYNC, 0, 3)}; |
| 19164 | |
| 19165 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19166 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19167 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19168 | |
| 19169 | AddSSLSocketData(); |
| 19170 | |
| 19171 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19172 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19173 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19174 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19175 | |
| 19176 | HttpRequestInfo request1; |
| 19177 | request1.method = "GET"; |
| 19178 | request1.url = GURL("https://www.example.org/"); |
| 19179 | request1.load_flags = 0; |
| 19180 | request1.traffic_annotation = |
| 19181 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19182 | auto trans1 = |
| 19183 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19184 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19185 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19186 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19187 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19188 | |
| 19189 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19190 | ASSERT_TRUE(response); |
| 19191 | ASSERT_TRUE(response->headers); |
| 19192 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19193 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19194 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19195 | std::string response_data; |
| 19196 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19197 | EXPECT_EQ("hello!", response_data); |
| 19198 | |
| 19199 | trans1.reset(); |
| 19200 | |
| 19201 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19202 | |
| 19203 | HttpRequestInfo request2; |
| 19204 | request2.method = "GET"; |
| 19205 | request2.url = GURL("https://mail.example.org/"); |
| 19206 | request2.load_flags = 0; |
| 19207 | request2.traffic_annotation = |
| 19208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19209 | auto trans2 = |
| 19210 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19211 | |
| 19212 | BoundTestNetLog log; |
| 19213 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19214 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19215 | |
| 19216 | response = trans2->GetResponseInfo(); |
| 19217 | ASSERT_TRUE(response); |
| 19218 | ASSERT_TRUE(response->headers); |
| 19219 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19220 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19221 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19222 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19223 | EXPECT_EQ("hello!", response_data); |
| 19224 | |
| 19225 | trans2.reset(); |
| 19226 | |
| 19227 | // One 200 report from the first request, then a 421 report from the |
| 19228 | // second request, then a 200 report from the successful retry. |
| 19229 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19230 | |
| 19231 | // Check error report contents |
| 19232 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19233 | network_error_logging_service()->errors()[0]; |
| 19234 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19235 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19236 | EXPECT_EQ("", error1.user_agent); |
| 19237 | EXPECT_EQ(ip, error1.server_ip); |
| 19238 | EXPECT_EQ("h2", error1.protocol); |
| 19239 | EXPECT_EQ("GET", error1.method); |
| 19240 | EXPECT_EQ(200, error1.status_code); |
| 19241 | EXPECT_EQ(OK, error1.type); |
| 19242 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19243 | |
| 19244 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19245 | network_error_logging_service()->errors()[1]; |
| 19246 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19247 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19248 | EXPECT_EQ("", error2.user_agent); |
| 19249 | EXPECT_EQ(ip, error2.server_ip); |
| 19250 | EXPECT_EQ("h2", error2.protocol); |
| 19251 | EXPECT_EQ("GET", error2.method); |
| 19252 | EXPECT_EQ(421, error2.status_code); |
| 19253 | EXPECT_EQ(OK, error2.type); |
| 19254 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19255 | |
| 19256 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19257 | network_error_logging_service()->errors()[2]; |
| 19258 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19259 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19260 | EXPECT_EQ("", error3.user_agent); |
| 19261 | EXPECT_EQ(ip, error3.server_ip); |
| 19262 | EXPECT_EQ("h2", error3.protocol); |
| 19263 | EXPECT_EQ("GET", error3.method); |
| 19264 | EXPECT_EQ(200, error3.status_code); |
| 19265 | EXPECT_EQ(OK, error3.type); |
| 19266 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19267 | } |
| 19268 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19269 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19270 | CreateReportCancelAfterStart) { |
| 19271 | StaticSocketDataProvider data; |
| 19272 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19273 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19274 | |
| 19275 | TestCompletionCallback callback; |
| 19276 | auto session = CreateSession(&session_deps_); |
| 19277 | auto trans = |
| 19278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19279 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19280 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19281 | |
| 19282 | // Cancel after start. |
| 19283 | trans.reset(); |
| 19284 | |
| 19285 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19286 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19287 | IPAddress() /* server_ip */); |
| 19288 | } |
| 19289 | |
| 19290 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19291 | CreateReportCancelBeforeReadingBody) { |
| 19292 | std::string extra_header_string = extra_headers_.ToString(); |
| 19293 | MockWrite data_writes[] = { |
| 19294 | MockWrite("GET / HTTP/1.1\r\n" |
| 19295 | "Host: www.example.org\r\n" |
| 19296 | "Connection: keep-alive\r\n"), |
| 19297 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19298 | }; |
| 19299 | MockRead data_reads[] = { |
| 19300 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19301 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19302 | }; |
| 19303 | |
| 19304 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19306 | |
| 19307 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19309 | |
| 19310 | TestCompletionCallback callback; |
| 19311 | auto session = CreateSession(&session_deps_); |
| 19312 | auto trans = |
| 19313 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19314 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19315 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19316 | |
| 19317 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19318 | ASSERT_TRUE(response); |
| 19319 | |
| 19320 | EXPECT_TRUE(response->headers); |
| 19321 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19322 | |
| 19323 | // Cancel before reading the body. |
| 19324 | trans.reset(); |
| 19325 | |
| 19326 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19327 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19328 | } |
| 19329 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19330 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19331 | base::HistogramTester histograms; |
| 19332 | RequestPolicy(); |
| 19333 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19334 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19335 | |
| 19336 | // Make HTTP request |
| 19337 | std::string extra_header_string = extra_headers_.ToString(); |
| 19338 | MockRead data_reads[] = { |
| 19339 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19340 | MockRead("hello world"), |
| 19341 | MockRead(SYNCHRONOUS, OK), |
| 19342 | }; |
| 19343 | MockWrite data_writes[] = { |
| 19344 | MockWrite("GET / HTTP/1.1\r\n" |
| 19345 | "Host: www.example.org\r\n" |
| 19346 | "Connection: keep-alive\r\n"), |
| 19347 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19348 | }; |
| 19349 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19350 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19352 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19353 | // Insecure url |
| 19354 | url_ = "http://www.example.org/"; |
| 19355 | request_.url = GURL(url_); |
| 19356 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19357 | TestCompletionCallback callback; |
| 19358 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19359 | auto trans = |
| 19360 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19361 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19362 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19363 | |
| 19364 | std::string response_data; |
| 19365 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19366 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19367 | |
| 19368 | // Insecure request does not generate a report |
| 19369 | histograms.ExpectBucketCount( |
| 19370 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19371 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19372 | |
| 19373 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19374 | } |
| 19375 | |
| 19376 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19377 | DontCreateReportHttpError) { |
| 19378 | base::HistogramTester histograms; |
| 19379 | RequestPolicy(); |
| 19380 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19381 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19382 | |
| 19383 | // Make HTTP request that fails |
| 19384 | MockRead data_reads[] = { |
| 19385 | MockRead("hello world"), |
| 19386 | MockRead(SYNCHRONOUS, OK), |
| 19387 | }; |
| 19388 | |
| 19389 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19390 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19391 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19392 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19393 | request_.url = GURL(url_); |
| 19394 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19396 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19397 | auto trans = |
| 19398 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19399 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19400 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19401 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19402 | |
| 19403 | // Insecure request does not generate a report, regardless of existence of a |
| 19404 | // policy for the origin. |
| 19405 | histograms.ExpectBucketCount( |
| 19406 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19407 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19408 | |
| 19409 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19410 | } |
| 19411 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19412 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19413 | // proxy. |
| 19414 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19415 | HttpRequestInfo request; |
| 19416 | request.method = "GET"; |
| 19417 | request.url = GURL("https://www.example.org/"); |
| 19418 | request.traffic_annotation = |
| 19419 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19420 | |
| 19421 | // Configure against proxy server "myproxy:70". |
| 19422 | session_deps_.proxy_resolution_service = |
| 19423 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19424 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19426 | |
| 19427 | // Since we have proxy, should try to establish tunnel. |
| 19428 | MockWrite data_writes1[] = { |
| 19429 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19430 | "Host: www.example.org:443\r\n" |
| 19431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19432 | }; |
| 19433 | |
| 19434 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19435 | // connection. |
| 19436 | MockRead data_reads1[] = { |
| 19437 | // No credentials. |
| 19438 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19439 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19440 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19441 | }; |
| 19442 | |
| 19443 | MockWrite data_writes2[] = { |
| 19444 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19445 | // be issuing -- the final header line contains the credentials. |
| 19446 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19447 | "Host: www.example.org:443\r\n" |
| 19448 | "Proxy-Connection: keep-alive\r\n" |
| 19449 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19450 | |
| 19451 | MockWrite("GET / HTTP/1.1\r\n" |
| 19452 | "Host: www.example.org\r\n" |
| 19453 | "Connection: keep-alive\r\n\r\n"), |
| 19454 | }; |
| 19455 | |
| 19456 | MockRead data_reads2[] = { |
| 19457 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19458 | |
| 19459 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19460 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19461 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19462 | MockRead(SYNCHRONOUS, "hello"), |
| 19463 | }; |
| 19464 | |
| 19465 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19466 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19467 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19468 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19469 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19471 | |
| 19472 | TestCompletionCallback callback1; |
| 19473 | |
| 19474 | auto trans = |
| 19475 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19476 | |
| 19477 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19478 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19479 | |
| 19480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19481 | EXPECT_EQ(407, response->headers->response_code()); |
| 19482 | |
| 19483 | std::string response_data; |
| 19484 | rv = ReadTransaction(trans.get(), &response_data); |
| 19485 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19486 | |
| 19487 | // No NEL report is generated for the 407. |
| 19488 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19489 | |
| 19490 | TestCompletionCallback callback2; |
| 19491 | |
| 19492 | rv = |
| 19493 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19494 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19495 | |
| 19496 | response = trans->GetResponseInfo(); |
| 19497 | EXPECT_EQ(200, response->headers->response_code()); |
| 19498 | |
| 19499 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19500 | EXPECT_EQ("hello", response_data); |
| 19501 | |
| 19502 | trans.reset(); |
| 19503 | |
| 19504 | // No NEL report is generated because we are behind a proxy. |
| 19505 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19506 | } |
| 19507 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19508 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19509 | ReportContainsUploadDepth) { |
| 19510 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19511 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19512 | RequestPolicy(); |
| 19513 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19514 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19515 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19516 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19517 | } |
| 19518 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19519 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19520 | std::string extra_header_string = extra_headers_.ToString(); |
| 19521 | static const base::TimeDelta kSleepDuration = |
| 19522 | base::TimeDelta::FromMilliseconds(10); |
| 19523 | |
| 19524 | std::vector<MockWrite> data_writes = { |
| 19525 | MockWrite(ASYNC, 0, |
| 19526 | "GET / HTTP/1.1\r\n" |
| 19527 | "Host: www.example.org\r\n" |
| 19528 | "Connection: keep-alive\r\n"), |
| 19529 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19530 | }; |
| 19531 | |
| 19532 | std::vector<MockRead> data_reads = { |
| 19533 | // Write one byte of the status line, followed by a pause. |
| 19534 | MockRead(ASYNC, 2, "H"), |
| 19535 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19536 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19537 | MockRead(ASYNC, 5, "hello world"), |
| 19538 | MockRead(SYNCHRONOUS, OK, 6), |
| 19539 | }; |
| 19540 | |
| 19541 | SequencedSocketData data(data_reads, data_writes); |
| 19542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19543 | |
| 19544 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19546 | |
| 19547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19548 | |
| 19549 | auto trans = |
| 19550 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19551 | |
| 19552 | TestCompletionCallback callback; |
| 19553 | |
| 19554 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19556 | |
| 19557 | data.RunUntilPaused(); |
| 19558 | ASSERT_TRUE(data.IsPaused()); |
| 19559 | FastForwardBy(kSleepDuration); |
| 19560 | data.Resume(); |
| 19561 | |
| 19562 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19563 | |
| 19564 | std::string response_data; |
| 19565 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19566 | EXPECT_EQ("hello world", response_data); |
| 19567 | |
| 19568 | trans.reset(); |
| 19569 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19570 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19571 | |
| 19572 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19573 | |
| 19574 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19575 | network_error_logging_service()->errors()[0]; |
| 19576 | |
| 19577 | // Sanity-check elapsed time in error report |
| 19578 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19579 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19580 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19581 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19582 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 19583 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 19584 | HttpRequestInfo request; |
| 19585 | request.method = "GET"; |
| 19586 | request.url = GURL("http://example.org/"); |
| 19587 | |
| 19588 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 19589 | |
| 19590 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19592 | TestCompletionCallback callback1; |
| 19593 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 19594 | |
| 19595 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 19596 | } |
| 19597 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19598 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 19599 | HttpRequestInfo request; |
| 19600 | request.method = "GET"; |
| 19601 | request.url = GURL("https://www.example.org/"); |
| 19602 | request.traffic_annotation = |
| 19603 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19604 | |
| 19605 | MockWrite data_writes[] = { |
| 19606 | MockWrite("GET / HTTP/1.1\r\n" |
| 19607 | "Host: www.example.org\r\n" |
| 19608 | "Connection: keep-alive\r\n\r\n"), |
| 19609 | }; |
| 19610 | |
| 19611 | // The proxy responds to the connect with a 407, using a persistent |
| 19612 | // connection. |
| 19613 | MockRead data_reads[] = { |
| 19614 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19615 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19616 | MockRead(SYNCHRONOUS, "1"), |
| 19617 | }; |
| 19618 | |
| 19619 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19621 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19622 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19623 | session_deps_.enable_early_data = true; |
| 19624 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19625 | |
| 19626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19627 | |
| 19628 | TestCompletionCallback callback; |
| 19629 | auto trans = |
| 19630 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19631 | |
| 19632 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19634 | |
| 19635 | rv = callback.WaitForResult(); |
| 19636 | EXPECT_THAT(rv, IsOk()); |
| 19637 | |
| 19638 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19639 | ASSERT_TRUE(response); |
| 19640 | ASSERT_TRUE(response->headers); |
| 19641 | EXPECT_EQ(200, response->headers->response_code()); |
| 19642 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19643 | |
| 19644 | // Check that ConfirmHandshake wasn't called. |
| 19645 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 19646 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 19647 | |
| 19648 | trans.reset(); |
| 19649 | |
| 19650 | session->CloseAllConnections(); |
| 19651 | } |
| 19652 | |
| 19653 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 19654 | HttpRequestInfo request; |
| 19655 | request.method = "POST"; |
| 19656 | request.url = GURL("https://www.example.org/"); |
| 19657 | request.traffic_annotation = |
| 19658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19659 | |
| 19660 | MockWrite data_writes[] = { |
| 19661 | MockWrite(SYNCHRONOUS, |
| 19662 | "POST / HTTP/1.1\r\n" |
| 19663 | "Host: www.example.org\r\n" |
| 19664 | "Connection: keep-alive\r\n" |
| 19665 | "Content-Length: 0\r\n\r\n"), |
| 19666 | }; |
| 19667 | |
| 19668 | // The proxy responds to the connect with a 407, using a persistent |
| 19669 | // connection. |
| 19670 | MockRead data_reads[] = { |
| 19671 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19672 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19673 | MockRead(SYNCHRONOUS, "1"), |
| 19674 | }; |
| 19675 | |
| 19676 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19678 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19679 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19680 | session_deps_.enable_early_data = true; |
| 19681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19682 | |
| 19683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19684 | |
| 19685 | TestCompletionCallback callback; |
| 19686 | auto trans = |
| 19687 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19688 | |
| 19689 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19691 | |
| 19692 | rv = callback.WaitForResult(); |
| 19693 | EXPECT_THAT(rv, IsOk()); |
| 19694 | |
| 19695 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19696 | ASSERT_TRUE(response); |
| 19697 | ASSERT_TRUE(response->headers); |
| 19698 | EXPECT_EQ(200, response->headers->response_code()); |
| 19699 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19700 | |
| 19701 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19702 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19703 | |
| 19704 | trans.reset(); |
| 19705 | |
| 19706 | session->CloseAllConnections(); |
| 19707 | } |
| 19708 | |
| 19709 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 19710 | HttpRequestInfo request; |
| 19711 | request.method = "POST"; |
| 19712 | request.url = GURL("https://www.example.org/"); |
| 19713 | request.traffic_annotation = |
| 19714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19715 | |
| 19716 | MockWrite data_writes[] = { |
| 19717 | MockWrite(ASYNC, |
| 19718 | "POST / HTTP/1.1\r\n" |
| 19719 | "Host: www.example.org\r\n" |
| 19720 | "Connection: keep-alive\r\n" |
| 19721 | "Content-Length: 0\r\n\r\n"), |
| 19722 | }; |
| 19723 | |
| 19724 | // The proxy responds to the connect with a 407, using a persistent |
| 19725 | // connection. |
| 19726 | MockRead data_reads[] = { |
| 19727 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19728 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19729 | MockRead(SYNCHRONOUS, "1"), |
| 19730 | }; |
| 19731 | |
| 19732 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19734 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19735 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19736 | session_deps_.enable_early_data = true; |
| 19737 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19738 | |
| 19739 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19740 | |
| 19741 | TestCompletionCallback callback; |
| 19742 | auto trans = |
| 19743 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19744 | |
| 19745 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19747 | |
| 19748 | rv = callback.WaitForResult(); |
| 19749 | EXPECT_THAT(rv, IsOk()); |
| 19750 | |
| 19751 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19752 | ASSERT_TRUE(response); |
| 19753 | ASSERT_TRUE(response->headers); |
| 19754 | EXPECT_EQ(200, response->headers->response_code()); |
| 19755 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19756 | |
| 19757 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19758 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19759 | |
| 19760 | trans.reset(); |
| 19761 | |
| 19762 | session->CloseAllConnections(); |
| 19763 | } |
| 19764 | |
| 19765 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 19766 | HttpRequestInfo request; |
| 19767 | request.method = "POST"; |
| 19768 | request.url = GURL("https://www.example.org/"); |
| 19769 | request.traffic_annotation = |
| 19770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19771 | |
| 19772 | MockWrite data_writes[] = { |
| 19773 | MockWrite(SYNCHRONOUS, |
| 19774 | "POST / HTTP/1.1\r\n" |
| 19775 | "Host: www.example.org\r\n" |
| 19776 | "Connection: keep-alive\r\n" |
| 19777 | "Content-Length: 0\r\n\r\n"), |
| 19778 | }; |
| 19779 | |
| 19780 | // The proxy responds to the connect with a 407, using a persistent |
| 19781 | // connection. |
| 19782 | MockRead data_reads[] = { |
| 19783 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19784 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19785 | MockRead(SYNCHRONOUS, "1"), |
| 19786 | }; |
| 19787 | |
| 19788 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19790 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19791 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19792 | session_deps_.enable_early_data = true; |
| 19793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19794 | |
| 19795 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19796 | |
| 19797 | TestCompletionCallback callback; |
| 19798 | auto trans = |
| 19799 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19800 | |
| 19801 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19803 | |
| 19804 | rv = callback.WaitForResult(); |
| 19805 | EXPECT_THAT(rv, IsOk()); |
| 19806 | |
| 19807 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19808 | ASSERT_TRUE(response); |
| 19809 | ASSERT_TRUE(response->headers); |
| 19810 | EXPECT_EQ(200, response->headers->response_code()); |
| 19811 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19812 | |
| 19813 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19814 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19815 | |
| 19816 | trans.reset(); |
| 19817 | |
| 19818 | session->CloseAllConnections(); |
| 19819 | } |
| 19820 | |
| 19821 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 19822 | HttpRequestInfo request; |
| 19823 | request.method = "POST"; |
| 19824 | request.url = GURL("https://www.example.org/"); |
| 19825 | request.traffic_annotation = |
| 19826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19827 | |
| 19828 | MockWrite data_writes[] = { |
| 19829 | MockWrite(ASYNC, |
| 19830 | "POST / HTTP/1.1\r\n" |
| 19831 | "Host: www.example.org\r\n" |
| 19832 | "Connection: keep-alive\r\n" |
| 19833 | "Content-Length: 0\r\n\r\n"), |
| 19834 | }; |
| 19835 | |
| 19836 | // The proxy responds to the connect with a 407, using a persistent |
| 19837 | // connection. |
| 19838 | MockRead data_reads[] = { |
| 19839 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19840 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19841 | MockRead(SYNCHRONOUS, "1"), |
| 19842 | }; |
| 19843 | |
| 19844 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19846 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19847 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19848 | session_deps_.enable_early_data = true; |
| 19849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19850 | |
| 19851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19852 | |
| 19853 | TestCompletionCallback callback; |
| 19854 | auto trans = |
| 19855 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19856 | |
| 19857 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19859 | |
| 19860 | rv = callback.WaitForResult(); |
| 19861 | EXPECT_THAT(rv, IsOk()); |
| 19862 | |
| 19863 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19864 | ASSERT_TRUE(response); |
| 19865 | ASSERT_TRUE(response->headers); |
| 19866 | EXPECT_EQ(200, response->headers->response_code()); |
| 19867 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19868 | |
| 19869 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19870 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19871 | |
| 19872 | trans.reset(); |
| 19873 | |
| 19874 | session->CloseAllConnections(); |
| 19875 | } |
| 19876 | |
| 19877 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 19878 | HttpRequestInfo request; |
| 19879 | request.method = "POST"; |
| 19880 | request.url = GURL("https://www.example.org/"); |
| 19881 | request.traffic_annotation = |
| 19882 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19883 | |
| 19884 | MockWrite data_writes[] = { |
| 19885 | MockWrite("POST / HTTP/1.1\r\n" |
| 19886 | "Host: www.example.org\r\n" |
| 19887 | "Connection: keep-alive\r\n" |
| 19888 | "Content-Length: 0\r\n\r\n"), |
| 19889 | }; |
| 19890 | |
| 19891 | // The proxy responds to the connect with a 407, using a persistent |
| 19892 | // connection. |
| 19893 | MockRead data_reads[] = { |
| 19894 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19895 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19896 | MockRead(SYNCHRONOUS, "1"), |
| 19897 | }; |
| 19898 | |
| 19899 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19901 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19902 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 19903 | session_deps_.enable_early_data = true; |
| 19904 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19905 | |
| 19906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19907 | |
| 19908 | TestCompletionCallback callback; |
| 19909 | auto trans = |
| 19910 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19911 | |
| 19912 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19914 | |
| 19915 | rv = callback.WaitForResult(); |
| 19916 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19917 | |
| 19918 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19919 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19920 | |
| 19921 | trans.reset(); |
| 19922 | |
| 19923 | session->CloseAllConnections(); |
| 19924 | } |
| 19925 | |
| 19926 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 19927 | HttpRequestInfo request; |
| 19928 | request.method = "POST"; |
| 19929 | request.url = GURL("https://www.example.org/"); |
| 19930 | request.traffic_annotation = |
| 19931 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19932 | |
| 19933 | MockWrite data_writes[] = { |
| 19934 | MockWrite("POST / HTTP/1.1\r\n" |
| 19935 | "Host: www.example.org\r\n" |
| 19936 | "Connection: keep-alive\r\n" |
| 19937 | "Content-Length: 0\r\n\r\n"), |
| 19938 | }; |
| 19939 | |
| 19940 | // The proxy responds to the connect with a 407, using a persistent |
| 19941 | // connection. |
| 19942 | MockRead data_reads[] = { |
| 19943 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19944 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19945 | MockRead(SYNCHRONOUS, "1"), |
| 19946 | }; |
| 19947 | |
| 19948 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19949 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19950 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19951 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 19952 | session_deps_.enable_early_data = true; |
| 19953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19954 | |
| 19955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19956 | |
| 19957 | TestCompletionCallback callback; |
| 19958 | auto trans = |
| 19959 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19960 | |
| 19961 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19963 | |
| 19964 | rv = callback.WaitForResult(); |
| 19965 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19966 | |
| 19967 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19968 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19969 | |
| 19970 | trans.reset(); |
| 19971 | |
| 19972 | session->CloseAllConnections(); |
| 19973 | } |
| 19974 | |
David Benjamin | 2eb827f | 2019-04-29 18:31:04 | [diff] [blame^] | 19975 | // Test the proxy and origin server each requesting both TLS client certificates |
| 19976 | // and HTTP auth. This is a regression test for https://crbug.com/946406. |
| 19977 | TEST_F(HttpNetworkTransactionTest, AuthEverything) { |
| 19978 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 19979 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 19980 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19981 | |
| 19982 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 19983 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 19984 | |
| 19985 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 19986 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 19987 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 19988 | ASSERT_TRUE(identity_proxy); |
| 19989 | |
| 19990 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 19991 | cert_request_info_origin->host_and_port = |
| 19992 | HostPortPair("www.example.org", 443); |
| 19993 | |
| 19994 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 19995 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 19996 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 19997 | ASSERT_TRUE(identity_origin); |
| 19998 | |
| 19999 | HttpRequestInfo request; |
| 20000 | request.method = "GET"; |
| 20001 | request.url = GURL("https://www.example.org/"); |
| 20002 | request.traffic_annotation = |
| 20003 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20004 | |
| 20005 | // First, the client connects to the proxy, which requests a client |
| 20006 | // certificate. |
| 20007 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20008 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20009 | ssl_proxy1.expected_send_client_cert = false; |
| 20010 | StaticSocketDataProvider data1; |
| 20011 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20012 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 20013 | |
| 20014 | // The client responds with a certificate on a new connection. The handshake |
| 20015 | // succeeds. |
| 20016 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20017 | ssl_proxy2.expected_send_client_cert = true; |
| 20018 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
| 20019 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20020 | std::vector<MockWrite> mock_writes2; |
| 20021 | std::vector<MockRead> mock_reads2; |
| 20022 | mock_writes2.emplace_back( |
| 20023 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20024 | "Host: www.example.org:443\r\n" |
| 20025 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20026 | mock_reads2.emplace_back( |
| 20027 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20028 | "Content-Length: 0\r\n" |
| 20029 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20030 | // The client retries with credentials. |
| 20031 | mock_writes2.emplace_back( |
| 20032 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20033 | "Host: www.example.org:443\r\n" |
| 20034 | "Proxy-Connection: keep-alive\r\n" |
| 20035 | // Authenticate as proxyuser:proxypass. |
| 20036 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20037 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20038 | // The origin requests client certificates. |
| 20039 | SSLSocketDataProvider ssl_origin2(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20040 | ssl_origin2.cert_request_info = cert_request_info_origin.get(); |
| 20041 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20042 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20044 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 20045 | |
| 20046 | // The client responds to the origin client certificate request on a new |
| 20047 | // connection. |
| 20048 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20049 | ssl_proxy3.expected_send_client_cert = true; |
| 20050 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 20051 | std::vector<MockWrite> mock_writes3; |
| 20052 | std::vector<MockRead> mock_reads3; |
| 20053 | mock_writes3.emplace_back( |
| 20054 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20055 | "Host: www.example.org:443\r\n" |
| 20056 | "Proxy-Connection: keep-alive\r\n" |
| 20057 | // Authenticate as proxyuser:proxypass. |
| 20058 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20059 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20060 | SSLSocketDataProvider ssl_origin3(ASYNC, OK); |
| 20061 | ssl_origin3.expected_send_client_cert = true; |
| 20062 | ssl_origin3.expected_client_cert = identity_origin->certificate(); |
| 20063 | // The client sends the origin HTTP request, which results in another HTTP |
| 20064 | // auth request. |
| 20065 | mock_writes3.emplace_back( |
| 20066 | "GET / HTTP/1.1\r\n" |
| 20067 | "Host: www.example.org\r\n" |
| 20068 | "Connection: keep-alive\r\n\r\n"); |
| 20069 | mock_reads3.emplace_back( |
| 20070 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20071 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20072 | "Content-Length: 0\r\n\r\n"); |
| 20073 | // The client retries with credentials, and the request finally succeeds. |
| 20074 | mock_writes3.emplace_back( |
| 20075 | "GET / HTTP/1.1\r\n" |
| 20076 | "Host: www.example.org\r\n" |
| 20077 | "Connection: keep-alive\r\n" |
| 20078 | // Authenticate as user:pass. |
| 20079 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20080 | mock_reads3.emplace_back( |
| 20081 | "HTTP/1.1 200 OK\r\n" |
| 20082 | "Content-Length: 0\r\n\r\n"); |
| 20083 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20084 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 20085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
| 20087 | |
| 20088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20089 | |
| 20090 | // Start the request. |
| 20091 | TestCompletionCallback callback; |
| 20092 | auto trans = |
| 20093 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20094 | int rv = callback.GetResult( |
| 20095 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20096 | |
| 20097 | // Handle the proxy client certificate challenge. |
| 20098 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20099 | SSLCertRequestInfo* cert_request_info = |
| 20100 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20101 | ASSERT_TRUE(cert_request_info); |
| 20102 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20103 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20104 | cert_request_info_proxy->host_and_port); |
| 20105 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20106 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20107 | callback.callback())); |
| 20108 | |
| 20109 | // Handle the proxy HTTP auth challenge. |
| 20110 | ASSERT_THAT(rv, IsOk()); |
| 20111 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20112 | EXPECT_TRUE( |
| 20113 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20114 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20115 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20116 | callback.callback())); |
| 20117 | |
| 20118 | // Handle the origin client certificate challenge. |
| 20119 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20120 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20121 | ASSERT_TRUE(cert_request_info); |
| 20122 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20123 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20124 | cert_request_info_origin->host_and_port); |
| 20125 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20126 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20127 | callback.callback())); |
| 20128 | |
| 20129 | // Handle the origin HTTP auth challenge. |
| 20130 | ASSERT_THAT(rv, IsOk()); |
| 20131 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20132 | EXPECT_TRUE( |
| 20133 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20134 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20135 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20136 | callback.callback())); |
| 20137 | |
| 20138 | // The request completes. |
| 20139 | ASSERT_THAT(rv, IsOk()); |
| 20140 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20141 | } |
| 20142 | |
| 20143 | // Test the proxy and origin server each requesting both TLS client certificates |
| 20144 | // and HTTP auth and each HTTP auth closing the connection. This is a regression |
| 20145 | // test for https://crbug.com/946406. |
| 20146 | TEST_F(HttpNetworkTransactionTest, AuthEverythingWithConnectClose) { |
| 20147 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20148 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20149 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20150 | |
| 20151 | auto cert_request_info_proxy = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20152 | cert_request_info_proxy->host_and_port = HostPortPair("myproxy", 70); |
| 20153 | |
| 20154 | std::unique_ptr<FakeClientCertIdentity> identity_proxy = |
| 20155 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20156 | GetTestCertsDirectory(), "client_1.pem", "client_1.pk8"); |
| 20157 | ASSERT_TRUE(identity_proxy); |
| 20158 | |
| 20159 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20160 | cert_request_info_origin->host_and_port = |
| 20161 | HostPortPair("www.example.org", 443); |
| 20162 | |
| 20163 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20164 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20165 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20166 | ASSERT_TRUE(identity_origin); |
| 20167 | |
| 20168 | HttpRequestInfo request; |
| 20169 | request.method = "GET"; |
| 20170 | request.url = GURL("https://www.example.org/"); |
| 20171 | request.traffic_annotation = |
| 20172 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20173 | |
| 20174 | // First, the client connects to the proxy, which requests a client |
| 20175 | // certificate. |
| 20176 | SSLSocketDataProvider ssl_proxy1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20177 | ssl_proxy1.cert_request_info = cert_request_info_proxy.get(); |
| 20178 | ssl_proxy1.expected_send_client_cert = false; |
| 20179 | StaticSocketDataProvider data1; |
| 20180 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20181 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 20182 | |
| 20183 | // The client responds with a certificate on a new connection. The handshake |
| 20184 | // succeeds. |
| 20185 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20186 | ssl_proxy2.expected_send_client_cert = true; |
| 20187 | ssl_proxy2.expected_client_cert = identity_proxy->certificate(); |
| 20188 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20189 | std::vector<MockWrite> mock_writes2; |
| 20190 | std::vector<MockRead> mock_reads2; |
| 20191 | mock_writes2.emplace_back( |
| 20192 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20193 | "Host: www.example.org:443\r\n" |
| 20194 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20195 | mock_reads2.emplace_back( |
| 20196 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20197 | "Content-Length: 0\r\n" |
| 20198 | "Proxy-Connection: close\r\n" |
| 20199 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20200 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20201 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20203 | |
| 20204 | // The client retries with credentials on a new connection. |
| 20205 | SSLSocketDataProvider ssl_proxy3(ASYNC, OK); |
| 20206 | ssl_proxy3.expected_send_client_cert = true; |
| 20207 | ssl_proxy3.expected_client_cert = identity_proxy->certificate(); |
| 20208 | std::vector<MockWrite> mock_writes3; |
| 20209 | std::vector<MockRead> mock_reads3; |
| 20210 | mock_writes3.emplace_back( |
| 20211 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20212 | "Host: www.example.org:443\r\n" |
| 20213 | "Proxy-Connection: keep-alive\r\n" |
| 20214 | // Authenticate as proxyuser:proxypass. |
| 20215 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20216 | mock_reads3.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20217 | // The origin requests client certificates. |
| 20218 | SSLSocketDataProvider ssl_origin3(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20219 | ssl_origin3.cert_request_info = cert_request_info_origin.get(); |
| 20220 | StaticSocketDataProvider data3(mock_reads3, mock_writes3); |
| 20221 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 20222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy3); |
| 20223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin3); |
| 20224 | |
| 20225 | // The client responds to the origin client certificate request on a new |
| 20226 | // connection. |
| 20227 | SSLSocketDataProvider ssl_proxy4(ASYNC, OK); |
| 20228 | ssl_proxy4.expected_send_client_cert = true; |
| 20229 | ssl_proxy4.expected_client_cert = identity_proxy->certificate(); |
| 20230 | std::vector<MockWrite> mock_writes4; |
| 20231 | std::vector<MockRead> mock_reads4; |
| 20232 | mock_writes4.emplace_back( |
| 20233 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20234 | "Host: www.example.org:443\r\n" |
| 20235 | "Proxy-Connection: keep-alive\r\n" |
| 20236 | // Authenticate as proxyuser:proxypass. |
| 20237 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20238 | mock_reads4.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20239 | SSLSocketDataProvider ssl_origin4(ASYNC, OK); |
| 20240 | ssl_origin4.expected_send_client_cert = true; |
| 20241 | ssl_origin4.expected_client_cert = identity_origin->certificate(); |
| 20242 | // The client sends the origin HTTP request, which results in another HTTP |
| 20243 | // auth request and closed connection. |
| 20244 | mock_writes4.emplace_back( |
| 20245 | "GET / HTTP/1.1\r\n" |
| 20246 | "Host: www.example.org\r\n" |
| 20247 | "Connection: keep-alive\r\n\r\n"); |
| 20248 | mock_reads4.emplace_back( |
| 20249 | "HTTP/1.1 401 Unauthorized\r\n" |
| 20250 | "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 20251 | "Connection: close\r\n" |
| 20252 | "Content-Length: 0\r\n\r\n"); |
| 20253 | StaticSocketDataProvider data4(mock_reads4, mock_writes4); |
| 20254 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
| 20255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy4); |
| 20256 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin4); |
| 20257 | |
| 20258 | // The client retries with credentials on a new connection, and the request |
| 20259 | // finally succeeds. |
| 20260 | SSLSocketDataProvider ssl_proxy5(ASYNC, OK); |
| 20261 | ssl_proxy5.expected_send_client_cert = true; |
| 20262 | ssl_proxy5.expected_client_cert = identity_proxy->certificate(); |
| 20263 | std::vector<MockWrite> mock_writes5; |
| 20264 | std::vector<MockRead> mock_reads5; |
| 20265 | mock_writes5.emplace_back( |
| 20266 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20267 | "Host: www.example.org:443\r\n" |
| 20268 | "Proxy-Connection: keep-alive\r\n" |
| 20269 | // Authenticate as proxyuser:proxypass. |
| 20270 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20271 | mock_reads5.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20272 | SSLSocketDataProvider ssl_origin5(ASYNC, OK); |
| 20273 | ssl_origin5.expected_send_client_cert = true; |
| 20274 | ssl_origin5.expected_client_cert = identity_origin->certificate(); |
| 20275 | mock_writes5.emplace_back( |
| 20276 | "GET / HTTP/1.1\r\n" |
| 20277 | "Host: www.example.org\r\n" |
| 20278 | "Connection: keep-alive\r\n" |
| 20279 | // Authenticate as user:pass. |
| 20280 | "Authorization: Basic dXNlcjpwYXNz\r\n\r\n"); |
| 20281 | mock_reads5.emplace_back( |
| 20282 | "HTTP/1.1 200 OK\r\n" |
| 20283 | "Connection: close\r\n" |
| 20284 | "Content-Length: 0\r\n\r\n"); |
| 20285 | StaticSocketDataProvider data5(mock_reads5, mock_writes5); |
| 20286 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 20287 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy5); |
| 20288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin5); |
| 20289 | |
| 20290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20291 | |
| 20292 | // Start the request. |
| 20293 | TestCompletionCallback callback; |
| 20294 | auto trans = |
| 20295 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20296 | int rv = callback.GetResult( |
| 20297 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20298 | |
| 20299 | // Handle the proxy client certificate challenge. |
| 20300 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20301 | SSLCertRequestInfo* cert_request_info = |
| 20302 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20303 | ASSERT_TRUE(cert_request_info); |
| 20304 | EXPECT_TRUE(cert_request_info->is_proxy); |
| 20305 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20306 | cert_request_info_proxy->host_and_port); |
| 20307 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20308 | identity_proxy->certificate(), identity_proxy->ssl_private_key(), |
| 20309 | callback.callback())); |
| 20310 | |
| 20311 | // Handle the proxy HTTP auth challenge. |
| 20312 | ASSERT_THAT(rv, IsOk()); |
| 20313 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20314 | EXPECT_TRUE( |
| 20315 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20316 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20317 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20318 | callback.callback())); |
| 20319 | |
| 20320 | // Handle the origin client certificate challenge. |
| 20321 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20322 | cert_request_info = trans->GetResponseInfo()->cert_request_info.get(); |
| 20323 | ASSERT_TRUE(cert_request_info); |
| 20324 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20325 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20326 | cert_request_info_origin->host_and_port); |
| 20327 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20328 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20329 | callback.callback())); |
| 20330 | |
| 20331 | // Handle the origin HTTP auth challenge. |
| 20332 | ASSERT_THAT(rv, IsOk()); |
| 20333 | EXPECT_EQ(401, trans->GetResponseInfo()->headers->response_code()); |
| 20334 | EXPECT_TRUE( |
| 20335 | CheckBasicSecureServerAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20336 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20337 | AuthCredentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")), |
| 20338 | callback.callback())); |
| 20339 | |
| 20340 | // The request completes. |
| 20341 | ASSERT_THAT(rv, IsOk()); |
| 20342 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20343 | } |
| 20344 | |
| 20345 | // Test the proxy requesting HTTP auth and the server requesting TLS client |
| 20346 | // certificates. This is a regression test for https://crbug.com/946406. |
| 20347 | TEST_F(HttpNetworkTransactionTest, ProxyHTTPAndServerTLSAuth) { |
| 20348 | // Note these hosts must match the CheckBasic*Auth() functions. |
| 20349 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 20350 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20351 | |
| 20352 | auto cert_request_info_origin = base::MakeRefCounted<SSLCertRequestInfo>(); |
| 20353 | cert_request_info_origin->host_and_port = |
| 20354 | HostPortPair("www.example.org", 443); |
| 20355 | |
| 20356 | std::unique_ptr<FakeClientCertIdentity> identity_origin = |
| 20357 | FakeClientCertIdentity::CreateFromCertAndKeyFiles( |
| 20358 | GetTestCertsDirectory(), "client_2.pem", "client_2.pk8"); |
| 20359 | ASSERT_TRUE(identity_origin); |
| 20360 | |
| 20361 | HttpRequestInfo request; |
| 20362 | request.method = "GET"; |
| 20363 | request.url = GURL("https://www.example.org/"); |
| 20364 | request.traffic_annotation = |
| 20365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 20366 | |
| 20367 | // The client connects to the proxy. The handshake succeeds. |
| 20368 | SSLSocketDataProvider ssl_proxy1(ASYNC, OK); |
| 20369 | // The client attempts an HTTP CONNECT, but the proxy requests basic auth. |
| 20370 | std::vector<MockWrite> mock_writes1; |
| 20371 | std::vector<MockRead> mock_reads1; |
| 20372 | mock_writes1.emplace_back( |
| 20373 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20374 | "Host: www.example.org:443\r\n" |
| 20375 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 20376 | mock_reads1.emplace_back( |
| 20377 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 20378 | "Content-Length: 0\r\n" |
| 20379 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"); |
| 20380 | // The client retries with credentials, and the request finally succeeds. |
| 20381 | mock_writes1.emplace_back( |
| 20382 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20383 | "Host: www.example.org:443\r\n" |
| 20384 | "Proxy-Connection: keep-alive\r\n" |
| 20385 | // Authenticate as proxyuser:proxypass. |
| 20386 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20387 | mock_reads1.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20388 | // The origin requests client certificates. |
| 20389 | SSLSocketDataProvider ssl_origin1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| 20390 | ssl_origin1.cert_request_info = cert_request_info_origin.get(); |
| 20391 | StaticSocketDataProvider data1(mock_reads1, mock_writes1); |
| 20392 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 20393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy1); |
| 20394 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin1); |
| 20395 | |
| 20396 | // The client responds to the origin client certificate request on a new |
| 20397 | // connection. |
| 20398 | SSLSocketDataProvider ssl_proxy2(ASYNC, OK); |
| 20399 | std::vector<MockWrite> mock_writes2; |
| 20400 | std::vector<MockRead> mock_reads2; |
| 20401 | mock_writes2.emplace_back( |
| 20402 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 20403 | "Host: www.example.org:443\r\n" |
| 20404 | "Proxy-Connection: keep-alive\r\n" |
| 20405 | // Authenticate as proxyuser:proxypass. |
| 20406 | "Proxy-Authorization: Basic cHJveHl1c2VyOnByb3h5cGFzcw==\r\n\r\n"); |
| 20407 | mock_reads2.emplace_back("HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 20408 | SSLSocketDataProvider ssl_origin2(ASYNC, OK); |
| 20409 | ssl_origin2.expected_send_client_cert = true; |
| 20410 | ssl_origin2.expected_client_cert = identity_origin->certificate(); |
| 20411 | // The client sends the origin HTTP request, which succeeds. |
| 20412 | mock_writes2.emplace_back( |
| 20413 | "GET / HTTP/1.1\r\n" |
| 20414 | "Host: www.example.org\r\n" |
| 20415 | "Connection: keep-alive\r\n\r\n"); |
| 20416 | mock_reads2.emplace_back( |
| 20417 | "HTTP/1.1 200 OK\r\n" |
| 20418 | "Content-Length: 0\r\n\r\n"); |
| 20419 | StaticSocketDataProvider data2(mock_reads2, mock_writes2); |
| 20420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 20421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_proxy2); |
| 20422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_origin2); |
| 20423 | |
| 20424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 20425 | |
| 20426 | // Start the request. |
| 20427 | TestCompletionCallback callback; |
| 20428 | auto trans = |
| 20429 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 20430 | int rv = callback.GetResult( |
| 20431 | trans->Start(&request, callback.callback(), NetLogWithSource())); |
| 20432 | |
| 20433 | // Handle the proxy HTTP auth challenge. |
| 20434 | ASSERT_THAT(rv, IsOk()); |
| 20435 | EXPECT_EQ(407, trans->GetResponseInfo()->headers->response_code()); |
| 20436 | EXPECT_TRUE( |
| 20437 | CheckBasicSecureProxyAuth(trans->GetResponseInfo()->auth_challenge)); |
| 20438 | rv = callback.GetResult(trans->RestartWithAuth( |
| 20439 | AuthCredentials(ASCIIToUTF16("proxyuser"), ASCIIToUTF16("proxypass")), |
| 20440 | callback.callback())); |
| 20441 | |
| 20442 | // Handle the origin client certificate challenge. |
| 20443 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
| 20444 | SSLCertRequestInfo* cert_request_info = |
| 20445 | trans->GetResponseInfo()->cert_request_info.get(); |
| 20446 | ASSERT_TRUE(cert_request_info); |
| 20447 | EXPECT_FALSE(cert_request_info->is_proxy); |
| 20448 | EXPECT_EQ(cert_request_info->host_and_port, |
| 20449 | cert_request_info_origin->host_and_port); |
| 20450 | rv = callback.GetResult(trans->RestartWithCertificate( |
| 20451 | identity_origin->certificate(), identity_origin->ssl_private_key(), |
| 20452 | callback.callback())); |
| 20453 | |
| 20454 | // The request completes. |
| 20455 | ASSERT_THAT(rv, IsOk()); |
| 20456 | EXPECT_EQ(200, trans->GetResponseInfo()->headers->response_code()); |
| 20457 | } |
| 20458 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 20459 | } // namespace net |