[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" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 99 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 100 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 101 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 102 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 103 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 104 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 105 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 106 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 107 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 108 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 109 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 110 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 111 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 112 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 113 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 114 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 115 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 116 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 117 | #if defined(NTLM_PORTABLE) |
| 118 | #include "base/base64.h" |
| 119 | #include "net/ntlm/ntlm_test_data.h" |
| 120 | #endif |
| 121 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 122 | #if BUILDFLAG(ENABLE_REPORTING) |
| 123 | #include "net/network_error_logging/network_error_logging_service.h" |
| 124 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 125 | #include "net/reporting/reporting_cache.h" |
| 126 | #include "net/reporting/reporting_client.h" |
| 127 | #include "net/reporting/reporting_header_parser.h" |
| 128 | #include "net/reporting/reporting_service.h" |
| 129 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 130 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 131 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 132 | using net::test::IsError; |
| 133 | using net::test::IsOk; |
| 134 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 135 | using base::ASCIIToUTF16; |
| 136 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 137 | //----------------------------------------------------------------------------- |
| 138 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 139 | namespace net { |
| 140 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 141 | namespace { |
| 142 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 143 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 144 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 145 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 146 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 147 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 148 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 149 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 150 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 151 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 152 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 153 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 154 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 155 | const char kAlternativeServiceHttpHeader[] = |
| 156 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 157 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 158 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 159 | return session |
| 160 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 161 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 162 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 163 | } |
| 164 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 165 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 166 | return session |
| 167 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 168 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 169 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 172 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 173 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 174 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 175 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 176 | if (!params) |
| 177 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 178 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 179 | if (!params->GetList("headers", &header_list)) |
| 180 | return false; |
| 181 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 182 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 183 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 187 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 188 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 189 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 190 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 191 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 192 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 194 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 195 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 196 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 197 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 198 | |
| 199 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 200 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 201 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 203 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 204 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 207 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 208 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 209 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 210 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 212 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | |
| 214 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 215 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 216 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 217 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 218 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 219 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 220 | load_timing_info.send_start); |
| 221 | |
| 222 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 226 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 227 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 231 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 232 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 233 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 234 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 236 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | |
| 238 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 239 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 240 | load_timing_info.proxy_resolve_end); |
| 241 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 242 | load_timing_info.send_start); |
| 243 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 245 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 247 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 248 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 252 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 253 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 254 | int connect_timing_flags) { |
| 255 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 256 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | |
| 258 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 259 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 260 | load_timing_info.proxy_resolve_end); |
| 261 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 262 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 263 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 264 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 265 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 266 | load_timing_info.send_start); |
| 267 | |
| 268 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 270 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 271 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 272 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 273 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | } |
| 275 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 276 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 277 | // result to return. |
| 278 | class CapturingProxyResolver : public ProxyResolver { |
| 279 | public: |
| 280 | CapturingProxyResolver() |
| 281 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 282 | ~CapturingProxyResolver() override = default; |
| 283 | |
| 284 | int GetProxyForURL(const GURL& url, |
| 285 | ProxyInfo* results, |
| 286 | CompletionOnceCallback callback, |
| 287 | std::unique_ptr<Request>* request, |
| 288 | const NetLogWithSource& net_log) override { |
| 289 | results->UseProxyServer(proxy_server_); |
| 290 | resolved_.push_back(url); |
| 291 | return OK; |
| 292 | } |
| 293 | |
| 294 | // Sets whether the resolver should use direct connections, instead of a |
| 295 | // proxy. |
| 296 | void set_proxy_server(ProxyServer proxy_server) { |
| 297 | proxy_server_ = proxy_server; |
| 298 | } |
| 299 | |
| 300 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 301 | |
| 302 | private: |
| 303 | std::vector<GURL> resolved_; |
| 304 | |
| 305 | ProxyServer proxy_server_; |
| 306 | |
| 307 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 308 | }; |
| 309 | |
| 310 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 311 | public: |
| 312 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 313 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 314 | |
| 315 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 316 | std::unique_ptr<ProxyResolver>* resolver, |
| 317 | CompletionOnceCallback callback, |
| 318 | std::unique_ptr<Request>* request) override { |
| 319 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 320 | return OK; |
| 321 | } |
| 322 | |
| 323 | private: |
| 324 | ProxyResolver* resolver_; |
| 325 | }; |
| 326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 327 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 328 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 329 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 330 | } |
| 331 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 332 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 333 | public: |
| 334 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 335 | |
| 336 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 337 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 338 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 339 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 340 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 341 | return ERR_PAC_SCRIPT_FAILED; |
| 342 | } |
| 343 | }; |
| 344 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 345 | class TestSSLConfigService : public SSLConfigService { |
| 346 | public: |
| 347 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 348 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 349 | |
| 350 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 351 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 352 | bool CanShareConnectionWithClientCerts( |
| 353 | const std::string& hostname) const override { |
| 354 | return false; |
| 355 | } |
| 356 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 357 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 358 | SSLConfig config_; |
| 359 | }; |
| 360 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 361 | } // namespace |
| 362 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 363 | class HttpNetworkTransactionTest : public PlatformTest, |
| 364 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 365 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 366 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 367 | // Important to restore the per-pool limit first, since the pool limit must |
| 368 | // always be greater than group limit, and the tests reduce both limits. |
| 369 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 370 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 371 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 372 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 373 | } |
| 374 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 375 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 376 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 377 | : WithScopedTaskEnvironment( |
| 378 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 379 | base::test::ScopedTaskEnvironment::NowSource:: |
| 380 | MAIN_THREAD_MOCK_TIME), |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 381 | dummy_connect_job_params_( |
| 382 | nullptr /* client_socket_factory */, |
| 383 | nullptr /* host_resolver */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 384 | nullptr /* http_auth_cache */, |
| 385 | nullptr /* http_auth_handler_factory */, |
| 386 | nullptr /* spdy_session_pool */, |
Matt Menke | b5fb42b | 2019-03-22 17:26:13 | [diff] [blame] | 387 | nullptr /* quic_supported_versions */, |
Matt Menke | b88837e | 2019-03-20 11:50:40 | [diff] [blame] | 388 | nullptr /* quic_stream_factory */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 389 | nullptr /* proxy_delegate */, |
| 390 | nullptr /* http_user_agent_settings */, |
| 391 | SSLClientSocketContext(), |
| 392 | SSLClientSocketContext(), |
| 393 | nullptr /* socket_performance_watcher_factory */, |
| 394 | nullptr /* network_quality_estimator */, |
| 395 | nullptr /* net_log */, |
| 396 | nullptr /* websocket_endpoint_lock_manager */), |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 397 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 398 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 399 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 400 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 401 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 402 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 403 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 404 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 405 | struct SimpleGetHelperResult { |
| 406 | int rv; |
| 407 | std::string status_line; |
| 408 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 409 | int64_t total_received_bytes; |
| 410 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 411 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 412 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 413 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 414 | }; |
| 415 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 416 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 417 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 418 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 419 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 420 | // before incrementing the counter does not return a null value. |
| 421 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 422 | } |
| 423 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 424 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 425 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 426 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 427 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 428 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 429 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 430 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
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 | } |
| 433 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 434 | void Check100ResponseTiming(bool use_spdy); |
| 435 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 436 | // Either |write_failure| specifies a write failure or |read_failure| |
| 437 | // specifies a read failure when using a reused socket. In either case, the |
| 438 | // failure should cause the network transaction to resend the request, and the |
| 439 | // other argument should be NULL. |
| 440 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 441 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 442 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 443 | // Either |write_failure| specifies a write failure or |read_failure| |
| 444 | // specifies a read failure when using a reused socket. In either case, the |
| 445 | // failure should cause the network transaction to resend the request, and the |
| 446 | // other argument should be NULL. |
| 447 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 448 | const MockRead* read_failure, |
| 449 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 450 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 451 | SimpleGetHelperResult SimpleGetHelperForData( |
| 452 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 453 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 454 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 455 | HttpRequestInfo request; |
| 456 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 457 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 458 | request.traffic_annotation = |
| 459 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 460 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 461 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 462 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 465 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 466 | for (auto* provider : providers) { |
| 467 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 468 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 470 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 471 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 472 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 473 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 475 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 476 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 477 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 478 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 479 | |
| 480 | // Even in the failure cases that use this function, connections are always |
| 481 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 482 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 483 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 484 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 485 | if (out.rv != OK) |
| 486 | return out; |
| 487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 489 | // Can't use ASSERT_* inside helper functions like this, so |
| 490 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 491 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 492 | out.rv = ERR_UNEXPECTED; |
| 493 | return out; |
| 494 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 495 | out.status_line = response->headers->GetStatusLine(); |
| 496 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 497 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 498 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 499 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 500 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 501 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 502 | EXPECT_EQ(got_endpoint, |
| 503 | out.remote_endpoint_after_start.address().size() > 0); |
| 504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 505 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 506 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 507 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 508 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 509 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 510 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 511 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 512 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 513 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 514 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 515 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 516 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 517 | std::string line; |
| 518 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 519 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 520 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 521 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 522 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 523 | std::string value; |
| 524 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 525 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 526 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 527 | EXPECT_EQ("keep-alive", value); |
| 528 | |
| 529 | std::string response_headers; |
| 530 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 531 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 532 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 534 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 535 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 536 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 538 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 539 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 540 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 541 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 542 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 543 | MockWrite data_writes[] = { |
| 544 | MockWrite("GET / HTTP/1.1\r\n" |
| 545 | "Host: www.example.org\r\n" |
| 546 | "Connection: keep-alive\r\n\r\n"), |
| 547 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 548 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 549 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 550 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 551 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 552 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 553 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 554 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 555 | } |
| 556 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 557 | void AddSSLSocketData() { |
| 558 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 559 | ssl_.ssl_info.cert = |
| 560 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 561 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 563 | } |
| 564 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 565 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 566 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 567 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 568 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 569 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 570 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 571 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 572 | const CommonConnectJobParams dummy_connect_job_params_; |
| 573 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 574 | // These clocks are defined here, even though they're only used in the |
| 575 | // Reporting tests below, since they need to be destroyed after |
| 576 | // |session_deps_|. |
| 577 | base::SimpleTestClock clock_; |
| 578 | base::SimpleTestTickClock tick_clock_; |
| 579 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 580 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 581 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 582 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 583 | |
| 584 | // Original socket limits. Some tests set these. Safest to always restore |
| 585 | // them once each test has been run. |
| 586 | int old_max_group_sockets_; |
| 587 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 588 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 589 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 590 | namespace { |
| 591 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 592 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 593 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 594 | BeforeHeadersSentHandler() |
| 595 | : observed_before_headers_sent_with_proxy_(false), |
| 596 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 597 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 599 | HttpRequestHeaders* request_headers) { |
| 600 | observed_before_headers_sent_ = true; |
| 601 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 602 | !proxy_info.is_quic()) { |
| 603 | return; |
| 604 | } |
| 605 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 606 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 607 | } |
| 608 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 609 | bool observed_before_headers_sent_with_proxy() const { |
| 610 | return observed_before_headers_sent_with_proxy_; |
| 611 | } |
| 612 | |
| 613 | bool observed_before_headers_sent() const { |
| 614 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | std::string observed_proxy_server_uri() const { |
| 618 | return observed_proxy_server_uri_; |
| 619 | } |
| 620 | |
| 621 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 622 | bool observed_before_headers_sent_with_proxy_; |
| 623 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 624 | std::string observed_proxy_server_uri_; |
| 625 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 626 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 627 | }; |
| 628 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 629 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 630 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 631 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 632 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 633 | const int sizeof_row = strlen(row); |
| 634 | const int num_rows = static_cast<int>( |
| 635 | ceil(static_cast<float>(size) / sizeof_row)); |
| 636 | const int sizeof_data = num_rows * sizeof_row; |
| 637 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 638 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 639 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 640 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 641 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 642 | } |
| 643 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 644 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 645 | uint64_t MockGetMSTime() { |
| 646 | // Tue, 23 May 2017 20:13:07 +0000 |
| 647 | return 131400439870000000; |
| 648 | } |
| 649 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 650 | // Alternative functions that eliminate randomness and dependency on the local |
| 651 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 652 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 653 | // This is set to 0xaa because the client challenge for testing in |
| 654 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 655 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 658 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 659 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 660 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 661 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 662 | |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 663 | class CaptureGroupIdTransportSocketPool : public TransportClientSocketPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 664 | public: |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 665 | explicit CaptureGroupIdTransportSocketPool( |
| 666 | const CommonConnectJobParams* common_connect_job_params) |
| 667 | : TransportClientSocketPool(0, |
| 668 | 0, |
| 669 | base::TimeDelta(), |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame^] | 670 | ProxyServer::Direct(), |
| 671 | false /* is_for_websockets */, |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 672 | common_connect_job_params, |
| 673 | nullptr /* ssl_config_service */) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 674 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 675 | const ClientSocketPool::GroupId& last_group_id_received() const { |
| 676 | return last_group_id_; |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 677 | } |
| 678 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 679 | bool socket_requested() const { return socket_requested_; } |
| 680 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 681 | int RequestSocket( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 682 | const ClientSocketPool::GroupId& group_id, |
Matt Menke | bd12b7e | 2019-03-25 21:12:03 | [diff] [blame] | 683 | scoped_refptr<ClientSocketPool::SocketParams> socket_params, |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 684 | RequestPriority priority, |
| 685 | const SocketTag& socket_tag, |
| 686 | ClientSocketPool::RespectLimits respect_limits, |
| 687 | ClientSocketHandle* handle, |
| 688 | CompletionOnceCallback callback, |
| 689 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 690 | const NetLogWithSource& net_log) override { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 691 | last_group_id_ = group_id; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 692 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 693 | return ERR_IO_PENDING; |
| 694 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 695 | void CancelRequest(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | ClientSocketHandle* handle) override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 697 | void ReleaseSocket(const ClientSocketPool::GroupId& group_id, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 698 | std::unique_ptr<StreamSocket> socket, |
Matt Menke | bf3c767d | 2019-04-15 23:28:24 | [diff] [blame] | 699 | int64_t generation) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 700 | void CloseIdleSockets() override {} |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 701 | void CloseIdleSocketsInGroup( |
| 702 | const ClientSocketPool::GroupId& group_id) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 703 | int IdleSocketCount() const override { return 0; } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 704 | size_t IdleSocketCountInGroup( |
| 705 | const ClientSocketPool::GroupId& group_id) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 706 | return 0; |
| 707 | } |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 708 | LoadState GetLoadState(const ClientSocketPool::GroupId& group_id, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 709 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 710 | return LOAD_STATE_IDLE; |
| 711 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 712 | |
| 713 | private: |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 714 | ClientSocketPool::GroupId last_group_id_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 715 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 716 | }; |
| 717 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | //----------------------------------------------------------------------------- |
| 719 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 720 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 721 | // configured for common cases. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 722 | bool CheckBasicServerAuth( |
| 723 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 724 | if (!auth_challenge) |
| 725 | return false; |
| 726 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 727 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 728 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 729 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 730 | return true; |
| 731 | } |
| 732 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 733 | bool CheckBasicProxyAuth( |
| 734 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 735 | if (!auth_challenge) |
| 736 | return false; |
| 737 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 738 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 739 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 740 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 741 | return true; |
| 742 | } |
| 743 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 744 | bool CheckBasicSecureProxyAuth( |
| 745 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 746 | if (!auth_challenge) |
| 747 | return false; |
| 748 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 749 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 750 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 751 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | return true; |
| 753 | } |
| 754 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 755 | bool CheckDigestServerAuth( |
| 756 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | if (!auth_challenge) |
| 758 | return false; |
| 759 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 760 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 762 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | return true; |
| 764 | } |
| 765 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 766 | #if defined(NTLM_PORTABLE) |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 767 | bool CheckNTLMServerAuth( |
| 768 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 769 | if (!auth_challenge) |
| 770 | return false; |
| 771 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 772 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 773 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 774 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 775 | return true; |
| 776 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 777 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 778 | bool CheckNTLMProxyAuth( |
| 779 | const base::Optional<AuthChallengeInfo>& auth_challenge) { |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 780 | if (!auth_challenge) |
| 781 | return false; |
| 782 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 783 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 784 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 785 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 786 | return true; |
| 787 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 788 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 790 | } // namespace |
| 791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 792 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | } |
| 796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 797 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 798 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 799 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 800 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 803 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 804 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 805 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 806 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 807 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 808 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 809 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 810 | |
| 811 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 815 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 817 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 820 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 821 | EXPECT_THAT(out.rv, IsOk()); |
| 822 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 823 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 824 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 825 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 826 | } |
| 827 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 828 | // Response with no status line, and a weird port. Should fail by default. |
| 829 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 830 | MockRead data_reads[] = { |
| 831 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 832 | }; |
| 833 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 834 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 836 | |
| 837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 838 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 839 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 840 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 843 | request.method = "GET"; |
| 844 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 845 | request.traffic_annotation = |
| 846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 847 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 848 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 849 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 850 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 851 | } |
| 852 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 853 | // Tests that request info can be destroyed after the headers phase is complete. |
| 854 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 856 | auto trans = |
| 857 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 858 | |
| 859 | MockRead data_reads[] = { |
| 860 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 861 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 862 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 863 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 865 | |
| 866 | TestCompletionCallback callback; |
| 867 | |
| 868 | { |
| 869 | auto request = std::make_unique<HttpRequestInfo>(); |
| 870 | request->method = "GET"; |
| 871 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 872 | request->traffic_annotation = |
| 873 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 874 | |
| 875 | int rv = |
| 876 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 877 | |
| 878 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 879 | } // Let request info be destroyed. |
| 880 | |
| 881 | trans.reset(); |
| 882 | } |
| 883 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 884 | // Response with no status line, and a weird port. Option to allow weird ports |
| 885 | // enabled. |
| 886 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 889 | }; |
| 890 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 891 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 893 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 895 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 896 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 897 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 898 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 899 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 900 | request.method = "GET"; |
| 901 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 902 | request.traffic_annotation = |
| 903 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 904 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 905 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 906 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 907 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 908 | |
| 909 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 910 | ASSERT_TRUE(info->headers); |
| 911 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 912 | |
| 913 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 914 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 915 | } |
| 916 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 918 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 920 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 921 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 923 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 924 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 926 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 927 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 928 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 932 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 934 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 935 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 937 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 938 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 940 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 941 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 942 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 946 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 947 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 948 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 949 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 951 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 952 | EXPECT_THAT(out.rv, IsOk()); |
| 953 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 954 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 955 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 956 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 960 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 961 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 962 | MockRead("\n"), |
| 963 | MockRead("\n"), |
| 964 | MockRead("Q"), |
| 965 | MockRead("J"), |
| 966 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 967 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 968 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 969 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 970 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 971 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 972 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 973 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 974 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 978 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 979 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 980 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 982 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 983 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 984 | EXPECT_THAT(out.rv, IsOk()); |
| 985 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 986 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 987 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 988 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 992 | // persistent connection. The response should still terminate since a 204 |
| 993 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 995 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 996 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 997 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 998 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 999 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1000 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1001 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1002 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1003 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1004 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1005 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1006 | int64_t response_size = reads_size - strlen(junk); |
| 1007 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1008 | } |
| 1009 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1011 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1012 | std::string final_chunk = "0\r\n\r\n"; |
| 1013 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1014 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1015 | MockRead data_reads[] = { |
| 1016 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1017 | MockRead("5\r\nHello\r\n"), |
| 1018 | MockRead("1\r\n"), |
| 1019 | MockRead(" \r\n"), |
| 1020 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1021 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1023 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1024 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1025 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1026 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1027 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1028 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1029 | int64_t response_size = reads_size - extra_data.size(); |
| 1030 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1031 | } |
| 1032 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1033 | // Next tests deal with http://crbug.com/56344. |
| 1034 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1035 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1036 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1037 | MockRead data_reads[] = { |
| 1038 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1039 | MockRead("Content-Length: 10\r\n"), |
| 1040 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1042 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1043 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1044 | } |
| 1045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1046 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1047 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1048 | MockRead data_reads[] = { |
| 1049 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n"), |
| 1051 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1052 | MockRead("Hello"), |
| 1053 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1054 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1055 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1056 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1057 | EXPECT_EQ("Hello", out.response_data); |
| 1058 | } |
| 1059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1060 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1061 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1062 | // More than 2 dupes. |
| 1063 | { |
| 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"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1072 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1073 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
| 1075 | } |
| 1076 | // HTTP/1.0 |
| 1077 | { |
| 1078 | MockRead data_reads[] = { |
| 1079 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1083 | MockRead("Hello"), |
| 1084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1086 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1087 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1088 | EXPECT_EQ("Hello", out.response_data); |
| 1089 | } |
| 1090 | // 2 dupes and one mismatched. |
| 1091 | { |
| 1092 | MockRead data_reads[] = { |
| 1093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1094 | MockRead("Content-Length: 10\r\n"), |
| 1095 | MockRead("Content-Length: 10\r\n"), |
| 1096 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1097 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1098 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1099 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1103 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1104 | MultipleContentLengthHeadersTransferEncoding) { |
| 1105 | MockRead data_reads[] = { |
| 1106 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1107 | MockRead("Content-Length: 666\r\n"), |
| 1108 | MockRead("Content-Length: 1337\r\n"), |
| 1109 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1110 | MockRead("5\r\nHello\r\n"), |
| 1111 | MockRead("1\r\n"), |
| 1112 | MockRead(" \r\n"), |
| 1113 | MockRead("5\r\nworld\r\n"), |
| 1114 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1115 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1116 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1117 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1118 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1119 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1120 | EXPECT_EQ("Hello world", out.response_data); |
| 1121 | } |
| 1122 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1123 | // Next tests deal with http://crbug.com/98895. |
| 1124 | |
| 1125 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1126 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1127 | MockRead data_reads[] = { |
| 1128 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1129 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1130 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1131 | MockRead("Hello"), |
| 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] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1135 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1136 | EXPECT_EQ("Hello", out.response_data); |
| 1137 | } |
| 1138 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1139 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1140 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1141 | MockRead data_reads[] = { |
| 1142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1143 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1144 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1145 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1146 | MockRead("Hello"), |
| 1147 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1148 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1149 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1150 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1151 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1155 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1156 | MockRead data_reads[] = { |
| 1157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1158 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1159 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1160 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1161 | MockRead("Hello"), |
| 1162 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1163 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1164 | EXPECT_THAT(out.rv, |
| 1165 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1168 | // Checks that two identical Location headers result in no error. |
| 1169 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1170 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | MockRead data_reads[] = { |
| 1172 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1173 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1174 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1176 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | }; |
| 1178 | |
| 1179 | HttpRequestInfo request; |
| 1180 | request.method = "GET"; |
| 1181 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1182 | request.traffic_annotation = |
| 1183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1188 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1191 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1193 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1196 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1198 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1199 | ASSERT_TRUE(response); |
| 1200 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1202 | std::string url; |
| 1203 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1204 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1205 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | } |
| 1207 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1209 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | MockRead data_reads[] = { |
| 1211 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1212 | MockRead("Location: http://good.com/\r\n"), |
| 1213 | MockRead("Location: http://evil.com/\r\n"), |
| 1214 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1216 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1217 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1218 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1219 | } |
| 1220 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1221 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1222 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1223 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1224 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1225 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1226 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1227 | request.traffic_annotation = |
| 1228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1229 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1232 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1233 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1234 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1235 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1236 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1238 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1239 | "Host: www.example.org\r\n" |
| 1240 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | }; |
| 1242 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1243 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1244 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1246 | // No response body because the test stops reading here. |
| 1247 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | }; |
| 1249 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1250 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1253 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1255 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | |
| 1258 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1261 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1262 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | |
| 1264 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1265 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1267 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1268 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1269 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1270 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | |
| 1272 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1273 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1274 | bool has_server_header = response->headers->EnumerateHeader( |
| 1275 | &iter, "Server", &server_header); |
| 1276 | EXPECT_TRUE(has_server_header); |
| 1277 | EXPECT_EQ("Blah", server_header); |
| 1278 | |
| 1279 | // Reading should give EOF right away, since there is no message body |
| 1280 | // (despite non-zero content-length). |
| 1281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1282 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1284 | EXPECT_EQ("", response_data); |
| 1285 | } |
| 1286 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1287 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
| 1290 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1291 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1292 | MockRead("hello"), |
| 1293 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1294 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1295 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1297 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1298 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1300 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | "hello", "world" |
| 1302 | }; |
| 1303 | |
| 1304 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1305 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1307 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1308 | request.traffic_annotation = |
| 1309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1313 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1315 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
| 1318 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1319 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1321 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1322 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1324 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1325 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1326 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
| 1328 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1329 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1330 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1331 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | } |
| 1333 | } |
| 1334 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1335 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1336 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1337 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1338 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1339 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1340 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1341 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | request.method = "POST"; |
| 1343 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1344 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1345 | request.traffic_annotation = |
| 1346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1348 | // Check the upload progress returned before initialization is correct. |
| 1349 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1350 | EXPECT_EQ(0u, progress.size()); |
| 1351 | EXPECT_EQ(0u, progress.position()); |
| 1352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1355 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1357 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1358 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1359 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1360 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1362 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1365 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1367 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
| 1370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1371 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1374 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1376 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1380 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1381 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1382 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | } |
| 1384 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | // This test is almost the same as Ignores100 above, but the response contains |
| 1386 | // 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] | 1387 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1388 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | request.method = "GET"; |
| 1391 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1392 | request.traffic_annotation = |
| 1393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1396 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1397 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1399 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1400 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1402 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1404 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1407 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1409 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | |
| 1412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1416 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1417 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1418 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1419 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1420 | |
| 1421 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1422 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1424 | EXPECT_EQ("hello world", response_data); |
| 1425 | } |
| 1426 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1427 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1428 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1429 | base::TimeDelta::FromMilliseconds(10); |
| 1430 | |
| 1431 | HttpRequestInfo request; |
| 1432 | request.method = "GET"; |
| 1433 | request.url = GURL("http://www.foo.com/"); |
| 1434 | request.traffic_annotation = |
| 1435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1436 | |
| 1437 | std::vector<MockWrite> data_writes = { |
| 1438 | MockWrite(ASYNC, 0, |
| 1439 | "GET / HTTP/1.1\r\n" |
| 1440 | "Host: www.foo.com\r\n" |
| 1441 | "Connection: keep-alive\r\n\r\n"), |
| 1442 | }; |
| 1443 | |
| 1444 | std::vector<MockRead> data_reads = { |
| 1445 | // Write one byte of the status line, followed by a pause. |
| 1446 | MockRead(ASYNC, 1, "H"), |
| 1447 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1448 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1449 | MockRead(ASYNC, 4, "hello world"), |
| 1450 | MockRead(SYNCHRONOUS, OK, 5), |
| 1451 | }; |
| 1452 | |
| 1453 | SequencedSocketData data(data_reads, data_writes); |
| 1454 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1455 | |
| 1456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1457 | |
| 1458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1459 | |
| 1460 | TestCompletionCallback callback; |
| 1461 | |
| 1462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1464 | |
| 1465 | data.RunUntilPaused(); |
| 1466 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1467 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1468 | data.Resume(); |
| 1469 | |
| 1470 | rv = callback.WaitForResult(); |
| 1471 | EXPECT_THAT(rv, IsOk()); |
| 1472 | |
| 1473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1474 | ASSERT_TRUE(response); |
| 1475 | |
| 1476 | EXPECT_TRUE(response->headers); |
| 1477 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1478 | |
| 1479 | LoadTimingInfo load_timing_info; |
| 1480 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1481 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1482 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1483 | // Ensure we didn't include the delay in the TTFB time. |
| 1484 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1485 | load_timing_info.connect_timing.connect_end); |
| 1486 | // Ensure that the mock clock advanced at all. |
| 1487 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1488 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1489 | |
| 1490 | std::string response_data; |
| 1491 | rv = ReadTransaction(&trans, &response_data); |
| 1492 | EXPECT_THAT(rv, IsOk()); |
| 1493 | EXPECT_EQ("hello world", response_data); |
| 1494 | } |
| 1495 | |
| 1496 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1497 | // info uses the first response, even if 1XX/informational. |
| 1498 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1499 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1500 | base::TimeDelta::FromMilliseconds(10); |
| 1501 | |
| 1502 | HttpRequestInfo request; |
| 1503 | request.method = "GET"; |
| 1504 | request.url = GURL("https://www.foo.com/"); |
| 1505 | request.traffic_annotation = |
| 1506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1507 | |
| 1508 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1510 | |
| 1511 | std::vector<MockWrite> data_writes; |
| 1512 | std::vector<MockRead> data_reads; |
| 1513 | |
| 1514 | spdy::SpdySerializedFrame spdy_req( |
| 1515 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1516 | |
| 1517 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1518 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1519 | spdy::SpdySerializedFrame spdy_resp1( |
| 1520 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1521 | spdy::SpdySerializedFrame spdy_resp2( |
| 1522 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1523 | spdy::SpdySerializedFrame spdy_data( |
| 1524 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1525 | |
| 1526 | if (use_spdy) { |
| 1527 | ssl.next_proto = kProtoHTTP2; |
| 1528 | |
| 1529 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1530 | |
| 1531 | data_reads = { |
| 1532 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1533 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1534 | MockRead(SYNCHRONOUS, OK, 5), |
| 1535 | }; |
| 1536 | } else { |
| 1537 | data_writes = { |
| 1538 | MockWrite(ASYNC, 0, |
| 1539 | "GET / HTTP/1.1\r\n" |
| 1540 | "Host: www.foo.com\r\n" |
| 1541 | "Connection: keep-alive\r\n\r\n"), |
| 1542 | }; |
| 1543 | |
| 1544 | data_reads = { |
| 1545 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1546 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1547 | |
| 1548 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1549 | MockRead(ASYNC, 4, "hello world"), |
| 1550 | MockRead(SYNCHRONOUS, OK, 5), |
| 1551 | }; |
| 1552 | } |
| 1553 | |
| 1554 | SequencedSocketData data(data_reads, data_writes); |
| 1555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1556 | |
| 1557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1558 | |
| 1559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1560 | |
| 1561 | TestCompletionCallback callback; |
| 1562 | |
| 1563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1565 | |
| 1566 | data.RunUntilPaused(); |
| 1567 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1568 | // the delay before parsing the 200 response. |
| 1569 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1570 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1571 | data.Resume(); |
| 1572 | |
| 1573 | rv = callback.WaitForResult(); |
| 1574 | EXPECT_THAT(rv, IsOk()); |
| 1575 | |
| 1576 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1577 | ASSERT_TRUE(response); |
| 1578 | |
| 1579 | LoadTimingInfo load_timing_info; |
| 1580 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1581 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1582 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1583 | // Ensure we didn't include the delay in the TTFB time. |
| 1584 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1585 | load_timing_info.connect_timing.connect_end); |
| 1586 | // Ensure that the mock clock advanced at all. |
| 1587 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1588 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1589 | |
| 1590 | std::string response_data; |
| 1591 | rv = ReadTransaction(&trans, &response_data); |
| 1592 | EXPECT_THAT(rv, IsOk()); |
| 1593 | EXPECT_EQ("hello world", response_data); |
| 1594 | } |
| 1595 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1596 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1597 | Check100ResponseTiming(false /* use_spdy */); |
| 1598 | } |
| 1599 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1600 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1601 | Check100ResponseTiming(true /* use_spdy */); |
| 1602 | } |
| 1603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1604 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1605 | HttpRequestInfo request; |
| 1606 | request.method = "POST"; |
| 1607 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1608 | request.traffic_annotation = |
| 1609 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1610 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1613 | |
| 1614 | MockRead data_reads[] = { |
| 1615 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1616 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1617 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1618 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1620 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1621 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1625 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1629 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1630 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1631 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1632 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | } |
| 1634 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1635 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1636 | HttpRequestInfo request; |
| 1637 | request.method = "POST"; |
| 1638 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1639 | request.traffic_annotation = |
| 1640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1644 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1645 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1646 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1647 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1648 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1649 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1651 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1653 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1655 | |
| 1656 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1657 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1660 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1661 | const MockWrite* write_failure, |
| 1662 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1663 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1664 | request.method = "GET"; |
| 1665 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1666 | request.traffic_annotation = |
| 1667 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1668 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1669 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1670 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1672 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1673 | // Written data for successfully sending both requests. |
| 1674 | MockWrite data1_writes[] = { |
| 1675 | MockWrite("GET / HTTP/1.1\r\n" |
| 1676 | "Host: www.foo.com\r\n" |
| 1677 | "Connection: keep-alive\r\n\r\n"), |
| 1678 | MockWrite("GET / HTTP/1.1\r\n" |
| 1679 | "Host: www.foo.com\r\n" |
| 1680 | "Connection: keep-alive\r\n\r\n") |
| 1681 | }; |
| 1682 | |
| 1683 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1684 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1685 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1686 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1687 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1688 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1689 | |
| 1690 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1691 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1692 | data1_writes[1] = *write_failure; |
| 1693 | } else { |
| 1694 | ASSERT_TRUE(read_failure); |
| 1695 | data1_reads[2] = *read_failure; |
| 1696 | } |
| 1697 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1698 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1700 | |
| 1701 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1702 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1703 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1704 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1706 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1707 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1708 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1709 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1710 | "hello", "world" |
| 1711 | }; |
| 1712 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1713 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1714 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1715 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1718 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1721 | |
| 1722 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1723 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1724 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1725 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1726 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1727 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1728 | if (i == 0) { |
| 1729 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1730 | } else { |
| 1731 | // The second request should be using a new socket. |
| 1732 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1733 | } |
| 1734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1735 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1736 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1737 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1738 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1739 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1740 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1741 | |
| 1742 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1743 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1744 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1745 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1746 | } |
| 1747 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1748 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1749 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1750 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1751 | const MockRead* read_failure, |
| 1752 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1753 | HttpRequestInfo request; |
| 1754 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1755 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1756 | request.traffic_annotation = |
| 1757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1759 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1760 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1762 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1764 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1765 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1766 | ssl1.next_proto = kProtoHTTP2; |
| 1767 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1768 | } |
| 1769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1771 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1772 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1773 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1774 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1775 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1776 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1777 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1778 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1779 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1780 | // HTTP/1.1 versions of the request and response. |
| 1781 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1782 | "Host: www.foo.com\r\n" |
| 1783 | "Connection: keep-alive\r\n\r\n"; |
| 1784 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1785 | const char kHttpData[] = "hello"; |
| 1786 | |
| 1787 | std::vector<MockRead> data1_reads; |
| 1788 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1789 | if (write_failure) { |
| 1790 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1791 | data1_writes.push_back(*write_failure); |
| 1792 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1793 | } else { |
| 1794 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1795 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1796 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1797 | } else { |
| 1798 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1799 | } |
| 1800 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | } |
| 1802 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1803 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1805 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1806 | std::vector<MockRead> data2_reads; |
| 1807 | std::vector<MockWrite> data2_writes; |
| 1808 | |
| 1809 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1810 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1811 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1812 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1813 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1814 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1815 | } else { |
| 1816 | data2_writes.push_back( |
| 1817 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1818 | |
| 1819 | data2_reads.push_back( |
| 1820 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1821 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1822 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1823 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1824 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1825 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1826 | |
| 1827 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1828 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1829 | // Wait for the preconnect to complete. |
| 1830 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1831 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1832 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
| 1834 | // Make the request. |
| 1835 | TestCompletionCallback callback; |
| 1836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1841 | |
| 1842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1844 | |
| 1845 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1846 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1847 | TestLoadTimingNotReused( |
| 1848 | load_timing_info, |
| 1849 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1851 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1852 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1853 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1854 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1855 | if (response->was_fetched_via_spdy) { |
| 1856 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1857 | } else { |
| 1858 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1859 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1860 | |
| 1861 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1862 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1864 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1865 | } |
| 1866 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1867 | // Test that we do not retry indefinitely when a server sends an error like |
| 1868 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1869 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1870 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1871 | HttpRequestInfo request; |
| 1872 | request.method = "GET"; |
| 1873 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1874 | request.traffic_annotation = |
| 1875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1876 | |
| 1877 | // Check whether we give up after the third try. |
| 1878 | |
| 1879 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1880 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1881 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1882 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1883 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1884 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1885 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1886 | |
| 1887 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1888 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1889 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1890 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1891 | |
| 1892 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1893 | AddSSLSocketData(); |
| 1894 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1895 | AddSSLSocketData(); |
| 1896 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1897 | AddSSLSocketData(); |
| 1898 | |
| 1899 | TestCompletionCallback callback; |
| 1900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1902 | |
| 1903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1905 | |
| 1906 | rv = callback.WaitForResult(); |
| 1907 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1908 | } |
| 1909 | |
| 1910 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1911 | HttpRequestInfo request; |
| 1912 | request.method = "GET"; |
| 1913 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1914 | request.traffic_annotation = |
| 1915 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1916 | |
| 1917 | // Check whether we try atleast thrice before giving up. |
| 1918 | |
| 1919 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1920 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1921 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1922 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1923 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1924 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1925 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1926 | |
| 1927 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1928 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1929 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1930 | spdy::SpdySerializedFrame spdy_data( |
| 1931 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1932 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1933 | CreateMockRead(spdy_data, 2)}; |
| 1934 | |
| 1935 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1936 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1937 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1938 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1939 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1940 | |
| 1941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1942 | AddSSLSocketData(); |
| 1943 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1944 | AddSSLSocketData(); |
| 1945 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1946 | AddSSLSocketData(); |
| 1947 | |
| 1948 | TestCompletionCallback callback; |
| 1949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1951 | |
| 1952 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1954 | |
| 1955 | rv = callback.WaitForResult(); |
| 1956 | EXPECT_THAT(rv, IsOk()); |
| 1957 | } |
| 1958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1959 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1960 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1961 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1962 | } |
| 1963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1964 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1965 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1966 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1967 | } |
| 1968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1969 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1970 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1971 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1972 | } |
| 1973 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1974 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1975 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1976 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1977 | MockRead read_failure(SYNCHRONOUS, |
| 1978 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1979 | "Connection: Keep-Alive\r\n" |
| 1980 | "Content-Length: 6\r\n\r\n" |
| 1981 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1982 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1983 | } |
| 1984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1985 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1986 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1987 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1988 | } |
| 1989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1990 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1991 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1992 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1993 | } |
| 1994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1995 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1996 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 1997 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1998 | } |
| 1999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2000 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2001 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2002 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2003 | } |
| 2004 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2005 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2006 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2007 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2008 | MockRead read_failure(SYNCHRONOUS, |
| 2009 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2010 | "Connection: Keep-Alive\r\n" |
| 2011 | "Content-Length: 6\r\n\r\n" |
| 2012 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2013 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2014 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2015 | } |
| 2016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2017 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2018 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2019 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | } |
| 2021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2022 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2023 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2024 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2025 | } |
| 2026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2027 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2028 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2029 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2030 | } |
| 2031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2032 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2033 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 2034 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2035 | } |
| 2036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2037 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2038 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2040 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2041 | request.traffic_annotation = |
| 2042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2046 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2048 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2049 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2050 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2051 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2052 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2053 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2056 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2057 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2058 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2060 | |
| 2061 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2062 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2063 | |
| 2064 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2065 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2066 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | // What do various browsers do when the server closes a non-keepalive |
| 2070 | // connection without sending any response header or body? |
| 2071 | // |
| 2072 | // IE7: error page |
| 2073 | // Safari 3.1.2 (Windows): error page |
| 2074 | // Firefox 3.0.1: blank page |
| 2075 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2076 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2077 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2078 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2079 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2080 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2081 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2082 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2083 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2086 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2087 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2088 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2089 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2090 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2091 | // destructor in such situations. |
| 2092 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2093 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2094 | HttpRequestInfo request; |
| 2095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2096 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2097 | request.traffic_annotation = |
| 2098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2101 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2102 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2103 | |
| 2104 | MockRead data_reads[] = { |
| 2105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2106 | MockRead("Connection: keep-alive\r\n"), |
| 2107 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2108 | MockRead("hello"), |
| 2109 | MockRead(SYNCHRONOUS, 0), |
| 2110 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2111 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | |
| 2114 | TestCompletionCallback callback; |
| 2115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2116 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2118 | |
| 2119 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2121 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2122 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2123 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2124 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2125 | if (rv == ERR_IO_PENDING) |
| 2126 | rv = callback.WaitForResult(); |
| 2127 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2128 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2129 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2130 | |
| 2131 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2132 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2133 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2134 | } |
| 2135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2136 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2137 | HttpRequestInfo request; |
| 2138 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2139 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2140 | request.traffic_annotation = |
| 2141 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2144 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2145 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2146 | |
| 2147 | MockRead data_reads[] = { |
| 2148 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2149 | MockRead("Connection: keep-alive\r\n"), |
| 2150 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2151 | MockRead(SYNCHRONOUS, 0), |
| 2152 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2153 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2155 | |
| 2156 | TestCompletionCallback callback; |
| 2157 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2158 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2159 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2160 | |
| 2161 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2162 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2163 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2164 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2165 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2166 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2167 | if (rv == ERR_IO_PENDING) |
| 2168 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2169 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2170 | |
| 2171 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2172 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2173 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2174 | } |
| 2175 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2176 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2177 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2178 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2179 | HttpRequestInfo request; |
| 2180 | request.method = "GET"; |
| 2181 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2182 | request.traffic_annotation = |
| 2183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2184 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2185 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2186 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2188 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2189 | const char* request_data = |
| 2190 | "GET / HTTP/1.1\r\n" |
| 2191 | "Host: www.foo.com\r\n" |
| 2192 | "Connection: keep-alive\r\n\r\n"; |
| 2193 | MockWrite data_writes[] = { |
| 2194 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2195 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2196 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2197 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2198 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2199 | }; |
| 2200 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2201 | // Note that because all these reads happen in the same |
| 2202 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2203 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2204 | MockRead data_reads[] = { |
| 2205 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2206 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2207 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2208 | MockRead(ASYNC, 7, |
| 2209 | "HTTP/1.1 302 Found\r\n" |
| 2210 | "Content-Length: 0\r\n\r\n"), |
| 2211 | MockRead(ASYNC, 9, |
| 2212 | "HTTP/1.1 302 Found\r\n" |
| 2213 | "Content-Length: 5\r\n\r\n" |
| 2214 | "hello"), |
| 2215 | MockRead(ASYNC, 11, |
| 2216 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2217 | "Content-Length: 0\r\n\r\n"), |
| 2218 | MockRead(ASYNC, 13, |
| 2219 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2220 | "Content-Length: 5\r\n\r\n" |
| 2221 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2222 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2223 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2224 | // the set_busy_before_sync_reads(true) call, while the |
| 2225 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2226 | // reuseable. See http://crbug.com/544255. |
| 2227 | MockRead(ASYNC, 15, |
| 2228 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2229 | "Content-Length: 5\r\n\r\n"), |
| 2230 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2231 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2232 | MockRead(ASYNC, 18, |
| 2233 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2234 | "Content-Length: 5\r\n\r\n" |
| 2235 | "he"), |
| 2236 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2237 | |
| 2238 | // The body of the final request is actually read. |
| 2239 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2240 | MockRead(ASYNC, 22, "hello"), |
| 2241 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2242 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2243 | data.set_busy_before_sync_reads(true); |
| 2244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2245 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2246 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2247 | std::string response_lines[kNumUnreadBodies]; |
| 2248 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2249 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2250 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2251 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2252 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2253 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2254 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2256 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2257 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2258 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2259 | LoadTimingInfo load_timing_info; |
| 2260 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2261 | if (i == 0) { |
| 2262 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2263 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2264 | } else { |
| 2265 | TestLoadTimingReused(load_timing_info); |
| 2266 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2267 | } |
| 2268 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2269 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2270 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2271 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2272 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2273 | response_lines[i] = response->headers->GetStatusLine(); |
| 2274 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2275 | // Delete the transaction without reading the response bodies. Then spin |
| 2276 | // the message loop, so the response bodies are drained. |
| 2277 | trans.reset(); |
| 2278 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2279 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2280 | |
| 2281 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2282 | "HTTP/1.1 204 No Content", |
| 2283 | "HTTP/1.1 205 Reset Content", |
| 2284 | "HTTP/1.1 304 Not Modified", |
| 2285 | "HTTP/1.1 302 Found", |
| 2286 | "HTTP/1.1 302 Found", |
| 2287 | "HTTP/1.1 301 Moved Permanently", |
| 2288 | "HTTP/1.1 301 Moved Permanently", |
| 2289 | "HTTP/1.1 200 Hunky-Dory", |
| 2290 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2291 | }; |
| 2292 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2293 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2294 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2295 | |
| 2296 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2297 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2299 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2301 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2304 | ASSERT_TRUE(response); |
| 2305 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2306 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2307 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2308 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2310 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2311 | } |
| 2312 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2313 | // Sockets that receive extra data after a response is complete should not be |
| 2314 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2315 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2317 | MockWrite data_writes1[] = { |
| 2318 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2319 | "Host: www.borked.com\r\n" |
| 2320 | "Connection: keep-alive\r\n\r\n"), |
| 2321 | }; |
| 2322 | |
| 2323 | MockRead data_reads1[] = { |
| 2324 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2325 | "Connection: keep-alive\r\n" |
| 2326 | "Content-Length: 22\r\n\r\n" |
| 2327 | "This server is borked."), |
| 2328 | }; |
| 2329 | |
| 2330 | MockWrite data_writes2[] = { |
| 2331 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2332 | "Host: www.borked.com\r\n" |
| 2333 | "Connection: keep-alive\r\n\r\n"), |
| 2334 | }; |
| 2335 | |
| 2336 | MockRead data_reads2[] = { |
| 2337 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2338 | "Content-Length: 3\r\n\r\n" |
| 2339 | "foo"), |
| 2340 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2341 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2342 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2343 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2345 | |
| 2346 | TestCompletionCallback callback; |
| 2347 | HttpRequestInfo request1; |
| 2348 | request1.method = "HEAD"; |
| 2349 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2350 | request1.traffic_annotation = |
| 2351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2352 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2353 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2354 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2355 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2357 | |
| 2358 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2359 | ASSERT_TRUE(response1); |
| 2360 | ASSERT_TRUE(response1->headers); |
| 2361 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2362 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2363 | |
| 2364 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2365 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2366 | EXPECT_EQ("", response_data1); |
| 2367 | // Deleting the transaction attempts to release the socket back into the |
| 2368 | // socket pool. |
| 2369 | trans1.reset(); |
| 2370 | |
| 2371 | HttpRequestInfo request2; |
| 2372 | request2.method = "GET"; |
| 2373 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2374 | request2.traffic_annotation = |
| 2375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2377 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2378 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2379 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2380 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2381 | |
| 2382 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2383 | ASSERT_TRUE(response2); |
| 2384 | ASSERT_TRUE(response2->headers); |
| 2385 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2386 | |
| 2387 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2388 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2389 | EXPECT_EQ("foo", response_data2); |
| 2390 | } |
| 2391 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2392 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2394 | MockWrite data_writes1[] = { |
| 2395 | MockWrite("GET / HTTP/1.1\r\n" |
| 2396 | "Host: www.borked.com\r\n" |
| 2397 | "Connection: keep-alive\r\n\r\n"), |
| 2398 | }; |
| 2399 | |
| 2400 | MockRead data_reads1[] = { |
| 2401 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2402 | "Connection: keep-alive\r\n" |
| 2403 | "Content-Length: 22\r\n\r\n" |
| 2404 | "This server is borked." |
| 2405 | "Bonus data!"), |
| 2406 | }; |
| 2407 | |
| 2408 | MockWrite data_writes2[] = { |
| 2409 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2410 | "Host: www.borked.com\r\n" |
| 2411 | "Connection: keep-alive\r\n\r\n"), |
| 2412 | }; |
| 2413 | |
| 2414 | MockRead data_reads2[] = { |
| 2415 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2416 | "Content-Length: 3\r\n\r\n" |
| 2417 | "foo"), |
| 2418 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2419 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2420 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2421 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2422 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2423 | |
| 2424 | TestCompletionCallback callback; |
| 2425 | HttpRequestInfo request1; |
| 2426 | request1.method = "GET"; |
| 2427 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2428 | request1.traffic_annotation = |
| 2429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2430 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2431 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2432 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2433 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2434 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2435 | |
| 2436 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2437 | ASSERT_TRUE(response1); |
| 2438 | ASSERT_TRUE(response1->headers); |
| 2439 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2440 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2441 | |
| 2442 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2443 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2444 | EXPECT_EQ("This server is borked.", response_data1); |
| 2445 | // Deleting the transaction attempts to release the socket back into the |
| 2446 | // socket pool. |
| 2447 | trans1.reset(); |
| 2448 | |
| 2449 | HttpRequestInfo request2; |
| 2450 | request2.method = "GET"; |
| 2451 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2452 | request2.traffic_annotation = |
| 2453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2454 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2455 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2456 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2457 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2458 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2459 | |
| 2460 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2461 | ASSERT_TRUE(response2); |
| 2462 | ASSERT_TRUE(response2->headers); |
| 2463 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2464 | |
| 2465 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2466 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2467 | EXPECT_EQ("foo", response_data2); |
| 2468 | } |
| 2469 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2470 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2472 | MockWrite data_writes1[] = { |
| 2473 | MockWrite("GET / HTTP/1.1\r\n" |
| 2474 | "Host: www.borked.com\r\n" |
| 2475 | "Connection: keep-alive\r\n\r\n"), |
| 2476 | }; |
| 2477 | |
| 2478 | MockRead data_reads1[] = { |
| 2479 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2480 | "Connection: keep-alive\r\n" |
| 2481 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2482 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2483 | MockRead("0\r\n\r\nBonus data!"), |
| 2484 | }; |
| 2485 | |
| 2486 | MockWrite data_writes2[] = { |
| 2487 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2488 | "Host: www.borked.com\r\n" |
| 2489 | "Connection: keep-alive\r\n\r\n"), |
| 2490 | }; |
| 2491 | |
| 2492 | MockRead data_reads2[] = { |
| 2493 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2494 | "Content-Length: 3\r\n\r\n" |
| 2495 | "foo"), |
| 2496 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2497 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2498 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2499 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2500 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2501 | |
| 2502 | TestCompletionCallback callback; |
| 2503 | HttpRequestInfo request1; |
| 2504 | request1.method = "GET"; |
| 2505 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2506 | request1.traffic_annotation = |
| 2507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2508 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2509 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2510 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2511 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2512 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2513 | |
| 2514 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2515 | ASSERT_TRUE(response1); |
| 2516 | ASSERT_TRUE(response1->headers); |
| 2517 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2518 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2519 | |
| 2520 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2521 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2522 | EXPECT_EQ("This server is borked.", response_data1); |
| 2523 | // Deleting the transaction attempts to release the socket back into the |
| 2524 | // socket pool. |
| 2525 | trans1.reset(); |
| 2526 | |
| 2527 | HttpRequestInfo request2; |
| 2528 | request2.method = "GET"; |
| 2529 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2530 | request2.traffic_annotation = |
| 2531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2532 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2533 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2534 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2535 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2536 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2537 | |
| 2538 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2539 | ASSERT_TRUE(response2); |
| 2540 | ASSERT_TRUE(response2->headers); |
| 2541 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2542 | |
| 2543 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2544 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2545 | EXPECT_EQ("foo", response_data2); |
| 2546 | } |
| 2547 | |
| 2548 | // This is a little different from the others - it tests the case that the |
| 2549 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2550 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2551 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2552 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2554 | MockWrite data_writes1[] = { |
| 2555 | MockWrite("GET / HTTP/1.1\r\n" |
| 2556 | "Host: www.borked.com\r\n" |
| 2557 | "Connection: keep-alive\r\n\r\n"), |
| 2558 | }; |
| 2559 | |
| 2560 | MockRead data_reads1[] = { |
| 2561 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2562 | "Connection: keep-alive\r\n" |
| 2563 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2564 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2565 | MockRead("0\r\n\r\nBonus data!"), |
| 2566 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2567 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2568 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2569 | |
| 2570 | TestCompletionCallback callback; |
| 2571 | HttpRequestInfo request1; |
| 2572 | request1.method = "GET"; |
| 2573 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2574 | request1.traffic_annotation = |
| 2575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2576 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2577 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2578 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2579 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2580 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2581 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2582 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2583 | ASSERT_TRUE(response1); |
| 2584 | ASSERT_TRUE(response1->headers); |
| 2585 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2586 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2587 | |
| 2588 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2589 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2590 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2591 | |
| 2592 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2593 | // socket can't be reused, rather than returning it to the socket pool. |
| 2594 | base::RunLoop().RunUntilIdle(); |
| 2595 | |
| 2596 | // There should be no idle sockets in the pool. |
| 2597 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2598 | } |
| 2599 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2600 | // Test the request-challenge-retry sequence for basic auth. |
| 2601 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2602 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2603 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2604 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2605 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2606 | request.traffic_annotation = |
| 2607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2608 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2609 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2610 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2613 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2614 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2615 | MockWrite( |
| 2616 | "GET / HTTP/1.1\r\n" |
| 2617 | "Host: www.example.org\r\n" |
| 2618 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2619 | }; |
| 2620 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2621 | MockRead data_reads1[] = { |
| 2622 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2623 | // Give a couple authenticate options (only the middle one is actually |
| 2624 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2625 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2627 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2629 | // Large content-length -- won't matter, as connection will be reset. |
| 2630 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2631 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2632 | }; |
| 2633 | |
| 2634 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2635 | // be issuing -- the final header line contains the credentials. |
| 2636 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2637 | MockWrite( |
| 2638 | "GET / HTTP/1.1\r\n" |
| 2639 | "Host: www.example.org\r\n" |
| 2640 | "Connection: keep-alive\r\n" |
| 2641 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2642 | }; |
| 2643 | |
| 2644 | // Lastly, the server responds with the actual content. |
| 2645 | MockRead data_reads2[] = { |
| 2646 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2647 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2648 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2649 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2650 | }; |
| 2651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2652 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2653 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2654 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2655 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2657 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2658 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2659 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2661 | |
| 2662 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2663 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2664 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2665 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2666 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2667 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2669 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2671 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2672 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2674 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2675 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2676 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2678 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2680 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2682 | |
| 2683 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2684 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2685 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2686 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2687 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2688 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2689 | // The load timing after restart should have a new socket ID, and times after |
| 2690 | // those of the first load timing. |
| 2691 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2692 | load_timing_info2.connect_timing.connect_start); |
| 2693 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2695 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2696 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2697 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2698 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2700 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2701 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2702 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2703 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2704 | } |
| 2705 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2706 | // Test the request-challenge-retry sequence for basic auth. |
| 2707 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2708 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2709 | HttpRequestInfo request; |
| 2710 | request.method = "GET"; |
| 2711 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2712 | request.traffic_annotation = |
| 2713 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2714 | |
| 2715 | TestNetLog log; |
| 2716 | MockHostResolver* resolver = new MockHostResolver(); |
| 2717 | session_deps_.net_log = &log; |
| 2718 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2719 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2721 | |
| 2722 | resolver->rules()->ClearRules(); |
| 2723 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2724 | |
| 2725 | MockWrite data_writes1[] = { |
| 2726 | MockWrite("GET / HTTP/1.1\r\n" |
| 2727 | "Host: www.example.org\r\n" |
| 2728 | "Connection: keep-alive\r\n\r\n"), |
| 2729 | }; |
| 2730 | |
| 2731 | MockRead data_reads1[] = { |
| 2732 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2733 | // Give a couple authenticate options (only the middle one is actually |
| 2734 | // supported). |
| 2735 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2736 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2737 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2738 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2739 | // Large content-length -- won't matter, as connection will be reset. |
| 2740 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2741 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2742 | }; |
| 2743 | |
| 2744 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2745 | // be issuing -- the final header line contains the credentials. |
| 2746 | MockWrite data_writes2[] = { |
| 2747 | MockWrite("GET / HTTP/1.1\r\n" |
| 2748 | "Host: www.example.org\r\n" |
| 2749 | "Connection: keep-alive\r\n" |
| 2750 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2751 | }; |
| 2752 | |
| 2753 | // Lastly, the server responds with the actual content. |
| 2754 | MockRead data_reads2[] = { |
| 2755 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2756 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2757 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2758 | }; |
| 2759 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2760 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2761 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2762 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2763 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2764 | |
| 2765 | TestCompletionCallback callback1; |
| 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2768 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2769 | |
| 2770 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2771 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2772 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2774 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2775 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2776 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2777 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2779 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2780 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2781 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2782 | |
| 2783 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2785 | ASSERT_FALSE(endpoint.address().empty()); |
| 2786 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2787 | |
| 2788 | resolver->rules()->ClearRules(); |
| 2789 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2790 | |
| 2791 | TestCompletionCallback callback2; |
| 2792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2793 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2794 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2795 | |
| 2796 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2798 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2799 | // The load timing after restart should have a new socket ID, and times after |
| 2800 | // those of the first load timing. |
| 2801 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2802 | load_timing_info2.connect_timing.connect_start); |
| 2803 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2804 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2805 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2806 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2807 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2808 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2810 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2811 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2812 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2813 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2815 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2816 | ASSERT_FALSE(endpoint.address().empty()); |
| 2817 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2818 | } |
| 2819 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2820 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2821 | // will eventually give up. |
| 2822 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2823 | HttpRequestInfo request; |
| 2824 | request.method = "GET"; |
| 2825 | request.url = GURL("http://www.example.org/"); |
| 2826 | request.traffic_annotation = |
| 2827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2828 | |
| 2829 | TestNetLog log; |
| 2830 | session_deps_.net_log = &log; |
| 2831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2833 | |
| 2834 | MockWrite data_writes[] = { |
| 2835 | MockWrite("GET / HTTP/1.1\r\n" |
| 2836 | "Host: www.example.org\r\n" |
| 2837 | "Connection: keep-alive\r\n\r\n"), |
| 2838 | }; |
| 2839 | |
| 2840 | MockRead data_reads[] = { |
| 2841 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2842 | // Give a couple authenticate options (only the middle one is actually |
| 2843 | // supported). |
| 2844 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2845 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2846 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2848 | // Large content-length -- won't matter, as connection will be reset. |
| 2849 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2850 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2851 | }; |
| 2852 | |
| 2853 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2854 | // be issuing -- the final header line contains the credentials. |
| 2855 | MockWrite data_writes_restart[] = { |
| 2856 | MockWrite("GET / HTTP/1.1\r\n" |
| 2857 | "Host: www.example.org\r\n" |
| 2858 | "Connection: keep-alive\r\n" |
| 2859 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2860 | }; |
| 2861 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2862 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2863 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2864 | |
| 2865 | TestCompletionCallback callback; |
| 2866 | int rv = callback.GetResult( |
| 2867 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2868 | |
| 2869 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2870 | for (int i = 0; i < 32; i++) { |
| 2871 | // Check the previous response was a 401. |
| 2872 | EXPECT_THAT(rv, IsOk()); |
| 2873 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2874 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2875 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2876 | |
| 2877 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2878 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2879 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2880 | data_restarts.back().get()); |
| 2881 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2882 | callback.callback())); |
| 2883 | } |
| 2884 | |
| 2885 | // After too many tries, the transaction should have given up. |
| 2886 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2887 | } |
| 2888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2889 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2890 | HttpRequestInfo request; |
| 2891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2892 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2893 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2894 | request.traffic_annotation = |
| 2895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2899 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2900 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2901 | MockWrite( |
| 2902 | "GET / HTTP/1.1\r\n" |
| 2903 | "Host: www.example.org\r\n" |
| 2904 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2905 | }; |
| 2906 | |
| 2907 | MockRead data_reads[] = { |
| 2908 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2909 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2910 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2911 | // Large content-length -- won't matter, as connection will be reset. |
| 2912 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2913 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2914 | }; |
| 2915 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2916 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2918 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2919 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2920 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2922 | |
| 2923 | rv = callback.WaitForResult(); |
| 2924 | EXPECT_EQ(0, rv); |
| 2925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2926 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2927 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2928 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2929 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2931 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2932 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2933 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2934 | } |
| 2935 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2937 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2938 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2939 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2940 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2941 | // reused. See http://crbug.com/544255. |
| 2942 | for (int i = 0; i < 2; ++i) { |
| 2943 | HttpRequestInfo request; |
| 2944 | request.method = "GET"; |
| 2945 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2946 | request.traffic_annotation = |
| 2947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2948 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2949 | TestNetLog log; |
| 2950 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2952 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2953 | MockWrite data_writes[] = { |
| 2954 | MockWrite(ASYNC, 0, |
| 2955 | "GET / HTTP/1.1\r\n" |
| 2956 | "Host: www.example.org\r\n" |
| 2957 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2959 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2960 | // be issuing -- the final header line contains the credentials. |
| 2961 | MockWrite(ASYNC, 6, |
| 2962 | "GET / HTTP/1.1\r\n" |
| 2963 | "Host: www.example.org\r\n" |
| 2964 | "Connection: keep-alive\r\n" |
| 2965 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2966 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2968 | MockRead data_reads[] = { |
| 2969 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2970 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2971 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2972 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2973 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2975 | // Lastly, the server responds with the actual content. |
| 2976 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2977 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2978 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2979 | MockRead(ASYNC, 10, "Hello"), |
| 2980 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2982 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2983 | data.set_busy_before_sync_reads(true); |
| 2984 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2985 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2986 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2989 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2990 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2991 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2992 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2994 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2997 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 2998 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2999 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3000 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3002 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3003 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3004 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3005 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3006 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3007 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3008 | TestLoadTimingReused(load_timing_info2); |
| 3009 | // The load timing after restart should have the same socket ID, and times |
| 3010 | // those of the first load timing. |
| 3011 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3012 | load_timing_info2.send_start); |
| 3013 | 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] | 3014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3015 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3016 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3017 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3018 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3019 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3020 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3021 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3022 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3023 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3024 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3025 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3026 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3027 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3031 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3032 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3033 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3035 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3036 | request.traffic_annotation = |
| 3037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3040 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3041 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3042 | MockWrite("GET / HTTP/1.1\r\n" |
| 3043 | "Host: www.example.org\r\n" |
| 3044 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3046 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3047 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3048 | MockWrite("GET / HTTP/1.1\r\n" |
| 3049 | "Host: www.example.org\r\n" |
| 3050 | "Connection: keep-alive\r\n" |
| 3051 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3052 | }; |
| 3053 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3054 | MockRead data_reads1[] = { |
| 3055 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3056 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3057 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | |
| 3059 | // Lastly, the server responds with the actual content. |
| 3060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3061 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3063 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | }; |
| 3065 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3066 | // An incorrect reconnect would cause this to be read. |
| 3067 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3068 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3069 | }; |
| 3070 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3071 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3072 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3074 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3076 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3079 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | |
| 3082 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3085 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3086 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3087 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3089 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3091 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3093 | |
| 3094 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3097 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3098 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3099 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3100 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3104 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3105 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3106 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3107 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3108 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3109 | request.traffic_annotation = |
| 3110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3113 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3114 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3115 | MockWrite("GET / HTTP/1.1\r\n" |
| 3116 | "Host: www.example.org\r\n" |
| 3117 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3119 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3120 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3121 | MockWrite("GET / HTTP/1.1\r\n" |
| 3122 | "Host: www.example.org\r\n" |
| 3123 | "Connection: keep-alive\r\n" |
| 3124 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3125 | }; |
| 3126 | |
| 3127 | // Respond with 5 kb of response body. |
| 3128 | std::string large_body_string("Unauthorized"); |
| 3129 | large_body_string.append(5 * 1024, ' '); |
| 3130 | large_body_string.append("\r\n"); |
| 3131 | |
| 3132 | MockRead data_reads1[] = { |
| 3133 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3134 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3135 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3136 | // 5134 = 12 + 5 * 1024 + 2 |
| 3137 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3138 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3139 | |
| 3140 | // Lastly, the server responds with the actual content. |
| 3141 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3142 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3143 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3144 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3145 | }; |
| 3146 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3147 | // An incorrect reconnect would cause this to be read. |
| 3148 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3149 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3150 | }; |
| 3151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3152 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3153 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3154 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3155 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3157 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3160 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | |
| 3163 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3166 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3167 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3168 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3170 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3172 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3174 | |
| 3175 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3178 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3179 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3180 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3181 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3185 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3186 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3187 | HttpRequestInfo request; |
| 3188 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3189 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3190 | request.traffic_annotation = |
| 3191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3194 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3195 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3196 | MockWrite( |
| 3197 | "GET / HTTP/1.1\r\n" |
| 3198 | "Host: www.example.org\r\n" |
| 3199 | "Connection: keep-alive\r\n\r\n"), |
| 3200 | // This simulates the seemingly successful write to a closed connection |
| 3201 | // if the bug is not fixed. |
| 3202 | MockWrite( |
| 3203 | "GET / HTTP/1.1\r\n" |
| 3204 | "Host: www.example.org\r\n" |
| 3205 | "Connection: keep-alive\r\n" |
| 3206 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3207 | }; |
| 3208 | |
| 3209 | MockRead data_reads1[] = { |
| 3210 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3211 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3212 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3213 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3214 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3215 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3216 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3217 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3218 | }; |
| 3219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3220 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3221 | // be issuing -- the final header line contains the credentials. |
| 3222 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3223 | MockWrite( |
| 3224 | "GET / HTTP/1.1\r\n" |
| 3225 | "Host: www.example.org\r\n" |
| 3226 | "Connection: keep-alive\r\n" |
| 3227 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3228 | }; |
| 3229 | |
| 3230 | // Lastly, the server responds with the actual content. |
| 3231 | MockRead data_reads2[] = { |
| 3232 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3233 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3234 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3235 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3236 | }; |
| 3237 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3238 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3239 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3241 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3243 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3246 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3248 | |
| 3249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3253 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3254 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3256 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3258 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3260 | |
| 3261 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3264 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3265 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3266 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3267 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3268 | } |
| 3269 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3270 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3271 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3272 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | HttpRequestInfo request; |
| 3274 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3275 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3276 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3277 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3278 | request.traffic_annotation = |
| 3279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | |
| 3281 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3282 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3283 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3284 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3285 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3288 | |
| 3289 | // Since we have proxy, should try to establish tunnel. |
| 3290 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3291 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3292 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3293 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | }; |
| 3295 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3296 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3297 | // connection. |
| 3298 | MockRead data_reads1[] = { |
| 3299 | // No credentials. |
| 3300 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3301 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3302 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3304 | // Since the first connection couldn't be reused, need to establish another |
| 3305 | // once given credentials. |
| 3306 | MockWrite data_writes2[] = { |
| 3307 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3308 | // be issuing -- the final header line contains the credentials. |
| 3309 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3310 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3311 | "Proxy-Connection: keep-alive\r\n" |
| 3312 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3313 | |
| 3314 | MockWrite("GET / HTTP/1.1\r\n" |
| 3315 | "Host: www.example.org\r\n" |
| 3316 | "Connection: keep-alive\r\n\r\n"), |
| 3317 | }; |
| 3318 | |
| 3319 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3320 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3321 | |
| 3322 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3323 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3324 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3325 | MockRead(SYNCHRONOUS, "hello"), |
| 3326 | }; |
| 3327 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3328 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3330 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3332 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3334 | |
| 3335 | TestCompletionCallback callback1; |
| 3336 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3337 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | |
| 3340 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3342 | |
| 3343 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3344 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3345 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | log.GetEntries(&entries); |
| 3347 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3348 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3349 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3350 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3351 | entries, pos, |
| 3352 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3353 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
| 3355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3356 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3357 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3358 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | EXPECT_EQ(407, response->headers->response_code()); |
| 3360 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3361 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
| 3363 | LoadTimingInfo load_timing_info; |
| 3364 | // CONNECT requests and responses are handled at the connect job level, so |
| 3365 | // the transaction does not yet have a connection. |
| 3366 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3367 | |
| 3368 | TestCompletionCallback callback2; |
| 3369 | |
| 3370 | rv = |
| 3371 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | |
| 3374 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3375 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | |
| 3377 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3378 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3379 | |
| 3380 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3381 | EXPECT_EQ(200, response->headers->response_code()); |
| 3382 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3383 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3384 | |
| 3385 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3386 | EXPECT_FALSE(response->auth_challenge.has_value()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3387 | |
| 3388 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3389 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3390 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3391 | |
| 3392 | trans.reset(); |
| 3393 | session->CloseAllConnections(); |
| 3394 | } |
| 3395 | |
| 3396 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3397 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3398 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3399 | HttpRequestInfo request; |
| 3400 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3401 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3402 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3403 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3404 | request.traffic_annotation = |
| 3405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3406 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3407 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3408 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3409 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3410 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3411 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3412 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3414 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3415 | // Since we have proxy, should try to establish tunnel. |
| 3416 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3417 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3418 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3419 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3420 | }; |
| 3421 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3422 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3423 | // connection. |
| 3424 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3425 | // No credentials. |
| 3426 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3427 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3428 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3429 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3430 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3431 | MockWrite data_writes2[] = { |
| 3432 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3433 | // be issuing -- the final header line contains the credentials. |
| 3434 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3435 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3436 | "Proxy-Connection: keep-alive\r\n" |
| 3437 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3438 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3439 | MockWrite("GET / HTTP/1.1\r\n" |
| 3440 | "Host: www.example.org\r\n" |
| 3441 | "Connection: keep-alive\r\n\r\n"), |
| 3442 | }; |
| 3443 | |
| 3444 | MockRead data_reads2[] = { |
| 3445 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3446 | |
| 3447 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3448 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3449 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3450 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3451 | }; |
| 3452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3453 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3454 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3455 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3456 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3457 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3458 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3460 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3461 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3462 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3463 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3465 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | |
| 3468 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3469 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3470 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3471 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3472 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3473 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3474 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3475 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3476 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3477 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3478 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3479 | |
| 3480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3481 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3482 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3483 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | EXPECT_EQ(407, response->headers->response_code()); |
| 3485 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3486 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3487 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3488 | LoadTimingInfo load_timing_info; |
| 3489 | // CONNECT requests and responses are handled at the connect job level, so |
| 3490 | // the transaction does not yet have a connection. |
| 3491 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3493 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3495 | rv = trans->RestartWithAuth( |
| 3496 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3498 | |
| 3499 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3501 | |
| 3502 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3503 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3504 | |
| 3505 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3506 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3507 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3508 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3509 | |
| 3510 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3511 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3512 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3513 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3514 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3515 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3516 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3517 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3518 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3519 | } |
| 3520 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3521 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3522 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3523 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3525 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3526 | // reused. See http://crbug.com/544255. |
| 3527 | for (int i = 0; i < 2; ++i) { |
| 3528 | HttpRequestInfo request; |
| 3529 | request.method = "GET"; |
| 3530 | request.url = GURL("https://www.example.org/"); |
| 3531 | // Ensure that proxy authentication is attempted even |
| 3532 | // when the no authentication data flag is set. |
| 3533 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3534 | request.traffic_annotation = |
| 3535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3538 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3539 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3540 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3541 | BoundTestNetLog log; |
| 3542 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3545 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3546 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | // Since we have proxy, should try to establish tunnel. |
| 3548 | MockWrite data_writes1[] = { |
| 3549 | MockWrite(ASYNC, 0, |
| 3550 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3551 | "Host: www.example.org:443\r\n" |
| 3552 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3554 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3555 | // be issuing -- the final header line contains the credentials. |
| 3556 | MockWrite(ASYNC, 3, |
| 3557 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3558 | "Host: www.example.org:443\r\n" |
| 3559 | "Proxy-Connection: keep-alive\r\n" |
| 3560 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3561 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3562 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3563 | // The proxy responds to the connect with a 407, using a persistent |
| 3564 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3565 | MockRead data_reads1[] = { |
| 3566 | // No credentials. |
| 3567 | MockRead(ASYNC, 1, |
| 3568 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3569 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3570 | "Proxy-Connection: keep-alive\r\n" |
| 3571 | "Content-Length: 10\r\n\r\n"), |
| 3572 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3573 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3574 | // Wrong credentials (wrong password). |
| 3575 | MockRead(ASYNC, 4, |
| 3576 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3577 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3578 | "Proxy-Connection: keep-alive\r\n" |
| 3579 | "Content-Length: 10\r\n\r\n"), |
| 3580 | // No response body because the test stops reading here. |
| 3581 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3582 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3583 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3584 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | data1.set_busy_before_sync_reads(true); |
| 3586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3587 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3588 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3590 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3591 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3592 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3593 | TestNetLogEntry::List entries; |
| 3594 | log.GetEntries(&entries); |
| 3595 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3596 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3597 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | ExpectLogContainsSomewhere( |
| 3599 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3600 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3601 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | ASSERT_TRUE(response); |
| 3605 | ASSERT_TRUE(response->headers); |
| 3606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3607 | EXPECT_EQ(407, response->headers->response_code()); |
| 3608 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3609 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3610 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3611 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3612 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3613 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3614 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3615 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3616 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3617 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
| 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
| 3624 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3625 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3626 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3627 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3629 | // out of scope. |
| 3630 | session->CloseAllConnections(); |
| 3631 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3635 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3636 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3638 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3639 | // reused. See http://crbug.com/544255. |
| 3640 | for (int i = 0; i < 2; ++i) { |
| 3641 | HttpRequestInfo request; |
| 3642 | request.method = "GET"; |
| 3643 | request.url = GURL("https://www.example.org/"); |
| 3644 | // Ensure that proxy authentication is attempted even |
| 3645 | // when the no authentication data flag is set. |
| 3646 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3647 | request.traffic_annotation = |
| 3648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3649 | |
| 3650 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3651 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3652 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3653 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3654 | BoundTestNetLog log; |
| 3655 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3658 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3659 | |
| 3660 | // Since we have proxy, should try to establish tunnel. |
| 3661 | MockWrite data_writes1[] = { |
| 3662 | MockWrite(ASYNC, 0, |
| 3663 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3664 | "Host: www.example.org:443\r\n" |
| 3665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3668 | // be issuing -- the final header line contains the credentials. |
| 3669 | MockWrite(ASYNC, 3, |
| 3670 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3671 | "Host: www.example.org:443\r\n" |
| 3672 | "Proxy-Connection: keep-alive\r\n" |
| 3673 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3674 | }; |
| 3675 | |
| 3676 | // The proxy responds to the connect with a 407, using a persistent |
| 3677 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3678 | MockRead data_reads1[] = { |
| 3679 | // No credentials. |
| 3680 | MockRead(ASYNC, 1, |
| 3681 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3682 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3683 | "Content-Length: 10\r\n\r\n"), |
| 3684 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3685 | |
| 3686 | // Wrong credentials (wrong password). |
| 3687 | MockRead(ASYNC, 4, |
| 3688 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3689 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3690 | "Content-Length: 10\r\n\r\n"), |
| 3691 | // No response body because the test stops reading here. |
| 3692 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3693 | }; |
| 3694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3695 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3696 | data1.set_busy_before_sync_reads(true); |
| 3697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3698 | |
| 3699 | TestCompletionCallback callback1; |
| 3700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3702 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3703 | |
| 3704 | TestNetLogEntry::List entries; |
| 3705 | log.GetEntries(&entries); |
| 3706 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3707 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3708 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3709 | ExpectLogContainsSomewhere( |
| 3710 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3711 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3712 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3714 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3715 | ASSERT_TRUE(response); |
| 3716 | ASSERT_TRUE(response->headers); |
| 3717 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3718 | EXPECT_EQ(407, response->headers->response_code()); |
| 3719 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3720 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3721 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3722 | EXPECT_FALSE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3723 | |
| 3724 | TestCompletionCallback callback2; |
| 3725 | |
| 3726 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3727 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3728 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3729 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3731 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3732 | ASSERT_TRUE(response); |
| 3733 | ASSERT_TRUE(response->headers); |
| 3734 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3735 | EXPECT_EQ(407, response->headers->response_code()); |
| 3736 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3737 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3738 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 3739 | EXPECT_TRUE(response->did_use_http_auth); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3740 | |
| 3741 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3742 | // out of scope. |
| 3743 | session->CloseAllConnections(); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3748 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3749 | // the case the server sends extra data on the original socket, so it can't be |
| 3750 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3751 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3752 | HttpRequestInfo request; |
| 3753 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3754 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3755 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3756 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3757 | request.traffic_annotation = |
| 3758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3759 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3760 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3761 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3762 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3763 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3764 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3765 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3767 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3768 | // Since we have proxy, should try to establish tunnel. |
| 3769 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3770 | MockWrite(ASYNC, 0, |
| 3771 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3772 | "Host: www.example.org:443\r\n" |
| 3773 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3774 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3775 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3776 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3777 | // extra data, so the socket cannot be reused. |
| 3778 | MockRead data_reads1[] = { |
| 3779 | // No credentials. |
| 3780 | MockRead(ASYNC, 1, |
| 3781 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3782 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3783 | "Content-Length: 10\r\n\r\n"), |
| 3784 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3785 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3786 | }; |
| 3787 | |
| 3788 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3789 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3790 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3791 | MockWrite(ASYNC, 0, |
| 3792 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3793 | "Host: www.example.org:443\r\n" |
| 3794 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3795 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3796 | |
| 3797 | MockWrite(ASYNC, 2, |
| 3798 | "GET / HTTP/1.1\r\n" |
| 3799 | "Host: www.example.org\r\n" |
| 3800 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3801 | }; |
| 3802 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3803 | MockRead data_reads2[] = { |
| 3804 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3805 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3806 | MockRead(ASYNC, 3, |
| 3807 | "HTTP/1.1 200 OK\r\n" |
| 3808 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3809 | "Content-Length: 5\r\n\r\n"), |
| 3810 | // No response body because the test stops reading here. |
| 3811 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3812 | }; |
| 3813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3814 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3815 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3816 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3817 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3818 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3819 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3820 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3822 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3823 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3824 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3825 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3826 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3827 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3828 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3829 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3830 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3831 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3832 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3833 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3834 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3835 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3836 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3837 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3838 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3839 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3840 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3841 | ASSERT_TRUE(response); |
| 3842 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3843 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3844 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3845 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3846 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3847 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3848 | LoadTimingInfo load_timing_info; |
| 3849 | // CONNECT requests and responses are handled at the connect job level, so |
| 3850 | // the transaction does not yet have a connection. |
| 3851 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3853 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3854 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3855 | rv = |
| 3856 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3857 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3858 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3859 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3860 | EXPECT_EQ(200, response->headers->response_code()); |
| 3861 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3862 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3863 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3864 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3865 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3866 | |
| 3867 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3868 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3869 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3870 | |
| 3871 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3872 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3873 | } |
| 3874 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3875 | // Test the case a proxy closes a socket while the challenge body is being |
| 3876 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3877 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3878 | HttpRequestInfo request; |
| 3879 | request.method = "GET"; |
| 3880 | request.url = GURL("https://www.example.org/"); |
| 3881 | // Ensure that proxy authentication is attempted even |
| 3882 | // when the no authentication data flag is set. |
| 3883 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3884 | request.traffic_annotation = |
| 3885 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3886 | |
| 3887 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3888 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3889 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3890 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3893 | |
| 3894 | // Since we have proxy, should try to establish tunnel. |
| 3895 | MockWrite data_writes1[] = { |
| 3896 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3897 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3898 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3899 | }; |
| 3900 | |
| 3901 | // The proxy responds to the connect with a 407, using a persistent |
| 3902 | // connection. |
| 3903 | MockRead data_reads1[] = { |
| 3904 | // No credentials. |
| 3905 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3906 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3907 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3908 | // Server hands up in the middle of the body. |
| 3909 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3910 | }; |
| 3911 | |
| 3912 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3913 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3914 | // be issuing -- the final header line contains the credentials. |
| 3915 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3916 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3917 | "Proxy-Connection: keep-alive\r\n" |
| 3918 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3919 | |
| 3920 | MockWrite("GET / HTTP/1.1\r\n" |
| 3921 | "Host: www.example.org\r\n" |
| 3922 | "Connection: keep-alive\r\n\r\n"), |
| 3923 | }; |
| 3924 | |
| 3925 | MockRead data_reads2[] = { |
| 3926 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3927 | |
| 3928 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3929 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3930 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3931 | MockRead(SYNCHRONOUS, "hello"), |
| 3932 | }; |
| 3933 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3934 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3935 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3936 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3937 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3938 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3940 | |
| 3941 | TestCompletionCallback callback; |
| 3942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3943 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3944 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3946 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3947 | ASSERT_TRUE(response); |
| 3948 | ASSERT_TRUE(response->headers); |
| 3949 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3950 | EXPECT_EQ(407, response->headers->response_code()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 3951 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3953 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3954 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3956 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3957 | ASSERT_TRUE(response); |
| 3958 | ASSERT_TRUE(response->headers); |
| 3959 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3960 | EXPECT_EQ(200, response->headers->response_code()); |
| 3961 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3962 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3963 | EXPECT_EQ("hello", body); |
| 3964 | } |
| 3965 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3966 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3967 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3968 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3969 | HttpRequestInfo request; |
| 3970 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3971 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3972 | request.traffic_annotation = |
| 3973 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3974 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3975 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3976 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3977 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3982 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3983 | // Since we have proxy, should try to establish tunnel. |
| 3984 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3985 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3986 | "Host: www.example.org:443\r\n" |
| 3987 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3988 | }; |
| 3989 | |
| 3990 | // The proxy responds to the connect with a 407. |
| 3991 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3992 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3993 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3994 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3995 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3996 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3997 | }; |
| 3998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3999 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4002 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4006 | |
| 4007 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4008 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4010 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4011 | ASSERT_TRUE(response); |
| 4012 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4014 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4015 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4016 | |
| 4017 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4018 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4019 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4020 | |
| 4021 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4022 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4023 | } |
| 4024 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4025 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4026 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4027 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4028 | HttpRequestInfo request; |
| 4029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4030 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4031 | request.traffic_annotation = |
| 4032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4033 | |
| 4034 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4035 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4036 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4037 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4041 | |
| 4042 | // Since we have proxy, should try to establish tunnel. |
| 4043 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4044 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4045 | "Host: www.example.org:443\r\n" |
| 4046 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4047 | }; |
| 4048 | |
| 4049 | // The proxy responds to the connect with a 407. |
| 4050 | MockRead data_reads[] = { |
| 4051 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4052 | MockRead("X-Foo: bar\r\n"), |
| 4053 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4054 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4055 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4056 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4057 | }; |
| 4058 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4059 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4061 | |
| 4062 | TestCompletionCallback callback; |
| 4063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4064 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4066 | |
| 4067 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4068 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4070 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4071 | ASSERT_TRUE(response); |
| 4072 | ASSERT_TRUE(response->headers); |
| 4073 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4074 | EXPECT_EQ(407, response->headers->response_code()); |
| 4075 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4076 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4077 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4078 | |
| 4079 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4080 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4081 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4082 | |
| 4083 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4084 | session->CloseAllConnections(); |
| 4085 | } |
| 4086 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4087 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4088 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4089 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4090 | HttpRequestInfo request; |
| 4091 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4092 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4093 | request.traffic_annotation = |
| 4094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4095 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4096 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4098 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4099 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4100 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4101 | MockWrite( |
| 4102 | "GET / HTTP/1.1\r\n" |
| 4103 | "Host: www.example.org\r\n" |
| 4104 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4105 | }; |
| 4106 | |
| 4107 | MockRead data_reads1[] = { |
| 4108 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4109 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4110 | // Large content-length -- won't matter, as connection will be reset. |
| 4111 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4112 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4113 | }; |
| 4114 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4115 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4118 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4119 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4120 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4121 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4122 | |
| 4123 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4124 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4125 | } |
| 4126 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4127 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4128 | // through a non-authenticating proxy. The request should fail with |
| 4129 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4130 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4131 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4132 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4133 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4134 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4135 | HttpRequestInfo request; |
| 4136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4137 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4138 | request.traffic_annotation = |
| 4139 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4140 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4141 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4142 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4143 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4144 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4146 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4147 | // Since we have proxy, should try to establish tunnel. |
| 4148 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4149 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4150 | "Host: www.example.org:443\r\n" |
| 4151 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4152 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4153 | MockWrite("GET / HTTP/1.1\r\n" |
| 4154 | "Host: www.example.org\r\n" |
| 4155 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4156 | }; |
| 4157 | |
| 4158 | MockRead data_reads1[] = { |
| 4159 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4160 | |
| 4161 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4162 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4163 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4165 | }; |
| 4166 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4167 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4168 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4169 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4172 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4174 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4176 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4178 | |
| 4179 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4180 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4181 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4182 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4183 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4184 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4185 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4186 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4187 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4188 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4189 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4190 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4191 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4193 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4194 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4195 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4196 | HttpRequestInfo request; |
| 4197 | request.method = "GET"; |
| 4198 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4199 | request.traffic_annotation = |
| 4200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4201 | |
| 4202 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4203 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4204 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4205 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4206 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4207 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4209 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4210 | mock_handler->set_allows_default_credentials(true); |
| 4211 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4212 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4213 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4214 | |
| 4215 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4216 | NetLog net_log; |
| 4217 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4218 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4219 | |
| 4220 | // Since we have proxy, should try to establish tunnel. |
| 4221 | MockWrite data_writes1[] = { |
| 4222 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4223 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4225 | }; |
| 4226 | |
| 4227 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4228 | // connection. |
| 4229 | MockRead data_reads1[] = { |
| 4230 | // No credentials. |
| 4231 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4232 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4233 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4234 | }; |
| 4235 | |
| 4236 | // Since the first connection couldn't be reused, need to establish another |
| 4237 | // once given credentials. |
| 4238 | MockWrite data_writes2[] = { |
| 4239 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4240 | // be issuing -- the final header line contains the credentials. |
| 4241 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4242 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4243 | "Proxy-Connection: keep-alive\r\n" |
| 4244 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4245 | |
| 4246 | MockWrite("GET / HTTP/1.1\r\n" |
| 4247 | "Host: www.example.org\r\n" |
| 4248 | "Connection: keep-alive\r\n\r\n"), |
| 4249 | }; |
| 4250 | |
| 4251 | MockRead data_reads2[] = { |
| 4252 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4253 | |
| 4254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4256 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4257 | MockRead(SYNCHRONOUS, "hello"), |
| 4258 | }; |
| 4259 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4260 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4262 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4263 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4264 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4266 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4267 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4268 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4269 | |
| 4270 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4271 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4272 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4273 | |
| 4274 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4275 | ASSERT_TRUE(response); |
| 4276 | ASSERT_TRUE(response->headers); |
| 4277 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4278 | EXPECT_EQ(407, response->headers->response_code()); |
| 4279 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4280 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4281 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4282 | |
| 4283 | LoadTimingInfo load_timing_info; |
| 4284 | // CONNECT requests and responses are handled at the connect job level, so |
| 4285 | // the transaction does not yet have a connection. |
| 4286 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4287 | |
| 4288 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4289 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | response = trans->GetResponseInfo(); |
| 4291 | ASSERT_TRUE(response); |
| 4292 | ASSERT_TRUE(response->headers); |
| 4293 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4294 | EXPECT_EQ(200, response->headers->response_code()); |
| 4295 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4296 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4297 | |
| 4298 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4299 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4300 | |
| 4301 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4302 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4303 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4304 | |
| 4305 | trans.reset(); |
| 4306 | session->CloseAllConnections(); |
| 4307 | } |
| 4308 | |
| 4309 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4310 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4311 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4312 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4313 | HttpRequestInfo request; |
| 4314 | request.method = "GET"; |
| 4315 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4316 | request.traffic_annotation = |
| 4317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4318 | |
| 4319 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4320 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4321 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4322 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4323 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4324 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4325 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4326 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4327 | mock_handler->set_allows_default_credentials(true); |
| 4328 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4329 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4330 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4331 | |
| 4332 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4333 | NetLog net_log; |
| 4334 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4335 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4336 | |
| 4337 | // Should try to establish tunnel. |
| 4338 | MockWrite data_writes1[] = { |
| 4339 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4340 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4341 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4342 | |
| 4343 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4344 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4345 | "Proxy-Connection: keep-alive\r\n" |
| 4346 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4347 | }; |
| 4348 | |
| 4349 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4350 | // connection. |
| 4351 | MockRead data_reads1[] = { |
| 4352 | // No credentials. |
| 4353 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4354 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4355 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4356 | }; |
| 4357 | |
| 4358 | // Since the first connection was closed, need to establish another once given |
| 4359 | // credentials. |
| 4360 | MockWrite data_writes2[] = { |
| 4361 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4362 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4363 | "Proxy-Connection: keep-alive\r\n" |
| 4364 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4365 | |
| 4366 | MockWrite("GET / HTTP/1.1\r\n" |
| 4367 | "Host: www.example.org\r\n" |
| 4368 | "Connection: keep-alive\r\n\r\n"), |
| 4369 | }; |
| 4370 | |
| 4371 | MockRead data_reads2[] = { |
| 4372 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4373 | |
| 4374 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4375 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4376 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4377 | MockRead(SYNCHRONOUS, "hello"), |
| 4378 | }; |
| 4379 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4380 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4381 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4382 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4383 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4384 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4386 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4387 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4388 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4389 | |
| 4390 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4391 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4392 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4393 | |
| 4394 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4395 | ASSERT_TRUE(response); |
| 4396 | ASSERT_TRUE(response->headers); |
| 4397 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4398 | EXPECT_EQ(407, response->headers->response_code()); |
| 4399 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4400 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4401 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4402 | |
| 4403 | LoadTimingInfo load_timing_info; |
| 4404 | // CONNECT requests and responses are handled at the connect job level, so |
| 4405 | // the transaction does not yet have a connection. |
| 4406 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4407 | |
| 4408 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4409 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4410 | |
| 4411 | response = trans->GetResponseInfo(); |
| 4412 | ASSERT_TRUE(response); |
| 4413 | ASSERT_TRUE(response->headers); |
| 4414 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4415 | EXPECT_EQ(200, response->headers->response_code()); |
| 4416 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4417 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4418 | |
| 4419 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4420 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4421 | |
| 4422 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4423 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4424 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4425 | |
| 4426 | trans.reset(); |
| 4427 | session->CloseAllConnections(); |
| 4428 | } |
| 4429 | |
| 4430 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4431 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4432 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4433 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4434 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4435 | HttpRequestInfo request; |
| 4436 | request.method = "GET"; |
| 4437 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4438 | request.traffic_annotation = |
| 4439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4440 | |
| 4441 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4442 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4443 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4444 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4445 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4446 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4447 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4448 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4449 | mock_handler->set_allows_default_credentials(true); |
| 4450 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4451 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4452 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4453 | |
| 4454 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4455 | NetLog net_log; |
| 4456 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4457 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4458 | |
| 4459 | // Should try to establish tunnel. |
| 4460 | MockWrite data_writes1[] = { |
| 4461 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4462 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4463 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4464 | |
| 4465 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4466 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4467 | "Proxy-Connection: keep-alive\r\n" |
| 4468 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4469 | }; |
| 4470 | |
| 4471 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4472 | // second request is sent. |
| 4473 | MockRead data_reads1[] = { |
| 4474 | // No credentials. |
| 4475 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4476 | MockRead("Content-Length: 0\r\n"), |
| 4477 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4478 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4479 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4480 | }; |
| 4481 | |
| 4482 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4483 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4484 | // request. |
| 4485 | MockWrite data_writes2[] = { |
| 4486 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4487 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4488 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4489 | }; |
| 4490 | |
| 4491 | // The proxy, having had more than enough of us, just hangs up. |
| 4492 | MockRead data_reads2[] = { |
| 4493 | // No credentials. |
| 4494 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4495 | }; |
| 4496 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4497 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4498 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4499 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4500 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4501 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4502 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4503 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4504 | |
| 4505 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4506 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4507 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4508 | |
| 4509 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4510 | ASSERT_TRUE(response); |
| 4511 | ASSERT_TRUE(response->headers); |
| 4512 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4513 | EXPECT_EQ(407, response->headers->response_code()); |
| 4514 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4515 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4516 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4517 | |
| 4518 | LoadTimingInfo load_timing_info; |
| 4519 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4520 | |
| 4521 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4522 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4523 | |
| 4524 | trans.reset(); |
| 4525 | session->CloseAllConnections(); |
| 4526 | } |
| 4527 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4528 | // This test exercises an odd edge case where the proxy closes the connection |
| 4529 | // after the authentication handshake is complete. Presumably this technique is |
| 4530 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4531 | // succeeds, but the user is not authorized to connect to the destination |
| 4532 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4533 | // site. |
| 4534 | TEST_F(HttpNetworkTransactionTest, |
| 4535 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4536 | HttpRequestInfo request; |
| 4537 | request.method = "GET"; |
| 4538 | request.url = GURL("https://www.example.org/"); |
| 4539 | request.traffic_annotation = |
| 4540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4541 | |
| 4542 | // Configure against proxy server "myproxy:70". |
| 4543 | session_deps_.proxy_resolution_service = |
| 4544 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4545 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4546 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4547 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4548 | // version interference probes. |
| 4549 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4550 | // test TLS 1.3. |
| 4551 | SSLConfig config; |
| 4552 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4553 | session_deps_.ssl_config_service = |
| 4554 | std::make_unique<TestSSLConfigService>(config); |
| 4555 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4556 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4557 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4558 | |
| 4559 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4560 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4561 | // was a real network error. |
| 4562 | // |
| 4563 | // The handlers support both default and explicit credentials. The retry |
| 4564 | // mentioned above should be able to reuse the default identity. Thus there |
| 4565 | // should never be a need to prompt for explicit credentials. |
| 4566 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4567 | mock_handler->set_allows_default_credentials(true); |
| 4568 | mock_handler->set_allows_explicit_credentials(true); |
| 4569 | mock_handler->set_connection_based(true); |
| 4570 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4571 | HttpAuth::AUTH_PROXY); |
| 4572 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4573 | mock_handler->set_allows_default_credentials(true); |
| 4574 | mock_handler->set_allows_explicit_credentials(true); |
| 4575 | mock_handler->set_connection_based(true); |
| 4576 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4577 | HttpAuth::AUTH_PROXY); |
| 4578 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4579 | |
| 4580 | NetLog net_log; |
| 4581 | session_deps_.net_log = &net_log; |
| 4582 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4583 | |
| 4584 | // Data for both sockets. |
| 4585 | // |
| 4586 | // Writes are for the tunnel establishment attempts and the |
| 4587 | // authentication handshake. |
| 4588 | MockWrite data_writes1[] = { |
| 4589 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4590 | "Host: www.example.org:443\r\n" |
| 4591 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4592 | |
| 4593 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4594 | "Host: www.example.org:443\r\n" |
| 4595 | "Proxy-Connection: keep-alive\r\n" |
| 4596 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4597 | |
| 4598 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4599 | "Host: www.example.org:443\r\n" |
| 4600 | "Proxy-Connection: keep-alive\r\n" |
| 4601 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4602 | }; |
| 4603 | |
| 4604 | // The server side of the authentication handshake. Note that the response to |
| 4605 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4606 | MockRead data_reads1[] = { |
| 4607 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4608 | MockRead("Content-Length: 0\r\n"), |
| 4609 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4610 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4611 | |
| 4612 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4613 | MockRead("Content-Length: 0\r\n"), |
| 4614 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4615 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4616 | |
| 4617 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4618 | }; |
| 4619 | |
| 4620 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4621 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4622 | |
| 4623 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4624 | // first attempt. |
| 4625 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4626 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4627 | |
| 4628 | auto trans = |
| 4629 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4630 | |
| 4631 | TestCompletionCallback callback; |
| 4632 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4633 | |
| 4634 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4635 | // stack. |
| 4636 | for (int i = 0; i < 4; ++i) { |
| 4637 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4638 | |
| 4639 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4640 | ASSERT_TRUE(response); |
| 4641 | ASSERT_TRUE(response->headers); |
| 4642 | EXPECT_EQ(407, response->headers->response_code()); |
| 4643 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4644 | |
| 4645 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4646 | } |
| 4647 | |
| 4648 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4649 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4650 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4651 | // being the first number, be reached, then lobbest thou thy |
| 4652 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4653 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4654 | |
| 4655 | trans.reset(); |
| 4656 | session->CloseAllConnections(); |
| 4657 | } |
| 4658 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4659 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4660 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4661 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4662 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4663 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4664 | HttpRequestInfo request; |
| 4665 | request.method = "GET"; |
| 4666 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4667 | request.traffic_annotation = |
| 4668 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4669 | |
| 4670 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4671 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4672 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4673 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4674 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4675 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4676 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4677 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4678 | mock_handler->set_allows_default_credentials(true); |
| 4679 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4680 | HttpAuth::AUTH_PROXY); |
| 4681 | // Add another handler for the second challenge. It supports default |
| 4682 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4683 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4684 | mock_handler->set_allows_default_credentials(true); |
| 4685 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4686 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4687 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4688 | |
| 4689 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4690 | NetLog net_log; |
| 4691 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4692 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4693 | |
| 4694 | // Should try to establish tunnel. |
| 4695 | MockWrite data_writes1[] = { |
| 4696 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4697 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4698 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4699 | }; |
| 4700 | |
| 4701 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4702 | // connection. |
| 4703 | MockRead data_reads1[] = { |
| 4704 | // No credentials. |
| 4705 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4706 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4707 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4708 | }; |
| 4709 | |
| 4710 | // Since the first connection was closed, need to establish another once given |
| 4711 | // credentials. |
| 4712 | MockWrite data_writes2[] = { |
| 4713 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4714 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4715 | "Proxy-Connection: keep-alive\r\n" |
| 4716 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4717 | }; |
| 4718 | |
| 4719 | MockRead data_reads2[] = { |
| 4720 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4721 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4722 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4723 | }; |
| 4724 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4725 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4726 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4727 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4728 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4729 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4731 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4732 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4733 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4734 | |
| 4735 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4736 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4737 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4738 | |
| 4739 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4740 | ASSERT_TRUE(response); |
| 4741 | ASSERT_TRUE(response->headers); |
| 4742 | EXPECT_EQ(407, response->headers->response_code()); |
| 4743 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4744 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4745 | EXPECT_FALSE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4746 | |
| 4747 | LoadTimingInfo load_timing_info; |
| 4748 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4749 | |
| 4750 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4751 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4752 | response = trans->GetResponseInfo(); |
| 4753 | ASSERT_TRUE(response); |
| 4754 | ASSERT_TRUE(response->headers); |
| 4755 | EXPECT_EQ(407, response->headers->response_code()); |
| 4756 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4757 | EXPECT_TRUE(response->auth_challenge.has_value()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4758 | |
| 4759 | trans.reset(); |
| 4760 | session->CloseAllConnections(); |
| 4761 | } |
| 4762 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4763 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4764 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4765 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4766 | // authentication handshake can continue with the same scheme but with a |
| 4767 | // different identity. |
| 4768 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4769 | HttpRequestInfo request; |
| 4770 | request.method = "GET"; |
| 4771 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4772 | request.traffic_annotation = |
| 4773 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4774 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4775 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4776 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4777 | |
| 4778 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4779 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4780 | mock_handler->set_allows_default_credentials(true); |
| 4781 | mock_handler->set_allows_explicit_credentials(true); |
| 4782 | mock_handler->set_connection_based(true); |
| 4783 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4784 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4785 | HttpAuth::AUTH_SERVER); |
| 4786 | |
| 4787 | // Add another handler for the second challenge. It supports default |
| 4788 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4789 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4790 | mock_handler->set_allows_default_credentials(true); |
| 4791 | mock_handler->set_allows_explicit_credentials(true); |
| 4792 | mock_handler->set_connection_based(true); |
| 4793 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4794 | HttpAuth::AUTH_SERVER); |
| 4795 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4796 | |
| 4797 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4798 | |
| 4799 | MockWrite data_writes1[] = { |
| 4800 | MockWrite("GET / HTTP/1.1\r\n" |
| 4801 | "Host: www.example.org\r\n" |
| 4802 | "Connection: keep-alive\r\n\r\n"), |
| 4803 | }; |
| 4804 | |
| 4805 | MockRead data_reads1[] = { |
| 4806 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4807 | "WWW-Authenticate: Mock\r\n" |
| 4808 | "Connection: keep-alive\r\n\r\n"), |
| 4809 | }; |
| 4810 | |
| 4811 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4812 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4813 | // transaction procceds without an authorization header. |
| 4814 | MockWrite data_writes2[] = { |
| 4815 | MockWrite("GET / HTTP/1.1\r\n" |
| 4816 | "Host: www.example.org\r\n" |
| 4817 | "Connection: keep-alive\r\n\r\n"), |
| 4818 | }; |
| 4819 | |
| 4820 | MockRead data_reads2[] = { |
| 4821 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4822 | "WWW-Authenticate: Mock\r\n" |
| 4823 | "Connection: keep-alive\r\n\r\n"), |
| 4824 | }; |
| 4825 | |
| 4826 | MockWrite data_writes3[] = { |
| 4827 | MockWrite("GET / HTTP/1.1\r\n" |
| 4828 | "Host: www.example.org\r\n" |
| 4829 | "Connection: keep-alive\r\n" |
| 4830 | "Authorization: auth_token\r\n\r\n"), |
| 4831 | }; |
| 4832 | |
| 4833 | MockRead data_reads3[] = { |
| 4834 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4835 | "Content-Length: 5\r\n" |
| 4836 | "Content-Type: text/plain\r\n" |
| 4837 | "Connection: keep-alive\r\n\r\n" |
| 4838 | "Hello"), |
| 4839 | }; |
| 4840 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4841 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4842 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4843 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4844 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4845 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4846 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4847 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4848 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4849 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4850 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4851 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4852 | |
| 4853 | TestCompletionCallback callback; |
| 4854 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4855 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4856 | |
| 4857 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4858 | ASSERT_TRUE(response); |
| 4859 | ASSERT_TRUE(response->headers); |
| 4860 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4861 | |
| 4862 | // The following three tests assert that an authentication challenge was |
| 4863 | // received and that the stack is ready to respond to the challenge using |
| 4864 | // ambient credentials. |
| 4865 | EXPECT_EQ(401, response->headers->response_code()); |
| 4866 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4867 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4868 | |
| 4869 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4870 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4871 | response = trans->GetResponseInfo(); |
| 4872 | ASSERT_TRUE(response); |
| 4873 | ASSERT_TRUE(response->headers); |
| 4874 | |
| 4875 | // The following three tests assert that an authentication challenge was |
| 4876 | // received and that the stack needs explicit credentials before it is ready |
| 4877 | // to respond to the challenge. |
| 4878 | EXPECT_EQ(401, response->headers->response_code()); |
| 4879 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4880 | EXPECT_TRUE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4881 | |
| 4882 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4883 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4884 | response = trans->GetResponseInfo(); |
| 4885 | ASSERT_TRUE(response); |
| 4886 | ASSERT_TRUE(response->headers); |
| 4887 | EXPECT_EQ(200, response->headers->response_code()); |
| 4888 | |
| 4889 | trans.reset(); |
| 4890 | session->CloseAllConnections(); |
| 4891 | } |
| 4892 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4893 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4894 | // schemes, based on the path of the URL being requests. |
| 4895 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4896 | public: |
| 4897 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4898 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4899 | |
| 4900 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4901 | |
| 4902 | static HostPortPair ProxyHostPortPair() { |
| 4903 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4904 | } |
| 4905 | |
| 4906 | // ProxyResolver implementation. |
| 4907 | int GetProxyForURL(const GURL& url, |
| 4908 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4909 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4910 | std::unique_ptr<Request>* request, |
| 4911 | const NetLogWithSource& /*net_log*/) override { |
| 4912 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4913 | results->set_traffic_annotation( |
| 4914 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4915 | if (url.path() == "/socks4") { |
| 4916 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4917 | return OK; |
| 4918 | } |
| 4919 | if (url.path() == "/socks5") { |
| 4920 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4921 | return OK; |
| 4922 | } |
| 4923 | if (url.path() == "/http") { |
| 4924 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4925 | return OK; |
| 4926 | } |
| 4927 | if (url.path() == "/https") { |
| 4928 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4929 | return OK; |
| 4930 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4931 | if (url.path() == "/https_trusted") { |
| 4932 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4933 | ProxyHostPortPair(), |
| 4934 | true /* is_trusted_proxy */)); |
| 4935 | return OK; |
| 4936 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4937 | NOTREACHED(); |
| 4938 | return ERR_NOT_IMPLEMENTED; |
| 4939 | } |
| 4940 | |
| 4941 | private: |
| 4942 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4943 | }; |
| 4944 | |
| 4945 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4946 | : public ProxyResolverFactory { |
| 4947 | public: |
| 4948 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4949 | : ProxyResolverFactory(false) {} |
| 4950 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4951 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4952 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4953 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4954 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4955 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4956 | return OK; |
| 4957 | } |
| 4958 | |
| 4959 | private: |
| 4960 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4961 | }; |
| 4962 | |
| 4963 | // 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] | 4964 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4965 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4966 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4967 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4968 | session_deps_.proxy_resolution_service = |
| 4969 | std::make_unique<ProxyResolutionService>( |
| 4970 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4971 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4972 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4973 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4974 | |
| 4975 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4976 | |
| 4977 | MockWrite socks_writes[] = { |
| 4978 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4979 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4980 | MockWrite(SYNCHRONOUS, |
| 4981 | "GET /socks4 HTTP/1.1\r\n" |
| 4982 | "Host: test\r\n" |
| 4983 | "Connection: keep-alive\r\n\r\n"), |
| 4984 | }; |
| 4985 | MockRead socks_reads[] = { |
| 4986 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4987 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4988 | "Connection: keep-alive\r\n" |
| 4989 | "Content-Length: 15\r\n\r\n" |
| 4990 | "SOCKS4 Response"), |
| 4991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4992 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4993 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4994 | |
| 4995 | const char kSOCKS5Request[] = { |
| 4996 | 0x05, // Version |
| 4997 | 0x01, // Command (CONNECT) |
| 4998 | 0x00, // Reserved |
| 4999 | 0x03, // Address type (DOMAINNAME) |
| 5000 | 0x04, // Length of domain (4) |
| 5001 | 't', 'e', 's', 't', // Domain string |
| 5002 | 0x00, 0x50, // 16-bit port (80) |
| 5003 | }; |
| 5004 | MockWrite socks5_writes[] = { |
| 5005 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5006 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5007 | MockWrite(SYNCHRONOUS, |
| 5008 | "GET /socks5 HTTP/1.1\r\n" |
| 5009 | "Host: test\r\n" |
| 5010 | "Connection: keep-alive\r\n\r\n"), |
| 5011 | }; |
| 5012 | MockRead socks5_reads[] = { |
| 5013 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5014 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5015 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5016 | "Connection: keep-alive\r\n" |
| 5017 | "Content-Length: 15\r\n\r\n" |
| 5018 | "SOCKS5 Response"), |
| 5019 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5020 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5021 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5022 | |
| 5023 | MockWrite http_writes[] = { |
| 5024 | MockWrite(SYNCHRONOUS, |
| 5025 | "GET http://test/http HTTP/1.1\r\n" |
| 5026 | "Host: test\r\n" |
| 5027 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5028 | }; |
| 5029 | MockRead http_reads[] = { |
| 5030 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5031 | "Proxy-Connection: keep-alive\r\n" |
| 5032 | "Content-Length: 13\r\n\r\n" |
| 5033 | "HTTP Response"), |
| 5034 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5035 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5036 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5037 | |
| 5038 | MockWrite https_writes[] = { |
| 5039 | MockWrite(SYNCHRONOUS, |
| 5040 | "GET http://test/https HTTP/1.1\r\n" |
| 5041 | "Host: test\r\n" |
| 5042 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5043 | }; |
| 5044 | MockRead https_reads[] = { |
| 5045 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5046 | "Proxy-Connection: keep-alive\r\n" |
| 5047 | "Content-Length: 14\r\n\r\n" |
| 5048 | "HTTPS Response"), |
| 5049 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5050 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5051 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5052 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5054 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5055 | MockWrite https_trusted_writes[] = { |
| 5056 | MockWrite(SYNCHRONOUS, |
| 5057 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5058 | "Host: test\r\n" |
| 5059 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5060 | }; |
| 5061 | MockRead https_trusted_reads[] = { |
| 5062 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5063 | "Proxy-Connection: keep-alive\r\n" |
| 5064 | "Content-Length: 22\r\n\r\n" |
| 5065 | "HTTPS Trusted Response"), |
| 5066 | }; |
| 5067 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5068 | https_trusted_writes); |
| 5069 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5070 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5072 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5073 | struct TestCase { |
| 5074 | GURL url; |
| 5075 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5076 | // 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] | 5077 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5078 | int expected_idle_socks4_sockets; |
| 5079 | int expected_idle_socks5_sockets; |
| 5080 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5081 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5082 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5083 | int expected_idle_https_sockets; |
| 5084 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5085 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5086 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5087 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5088 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5089 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5090 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5091 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5092 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5093 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5094 | }; |
| 5095 | |
| 5096 | for (const auto& test_case : kTestCases) { |
| 5097 | HttpRequestInfo request; |
| 5098 | request.method = "GET"; |
| 5099 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5100 | request.traffic_annotation = |
| 5101 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5102 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5103 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5104 | session.get()); |
| 5105 | TestCompletionCallback callback; |
| 5106 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5107 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5108 | |
| 5109 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5110 | ASSERT_TRUE(response); |
| 5111 | ASSERT_TRUE(response->headers); |
| 5112 | EXPECT_EQ(200, response->headers->response_code()); |
| 5113 | std::string response_data; |
| 5114 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5115 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5116 | |
| 5117 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5118 | // the next requests. |
| 5119 | trans.reset(); |
| 5120 | base::RunLoop().RunUntilIdle(); |
| 5121 | |
| 5122 | // Check the number of idle sockets in the pool, to make sure that used |
| 5123 | // sockets are indeed being returned to the socket pool. If each request |
| 5124 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5125 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5126 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5127 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5128 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5129 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5130 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5131 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5132 | ProxyHostPortPair())) |
| 5133 | ->IdleSocketCount()); |
| 5134 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5135 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5136 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5137 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5138 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5139 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5140 | ProxyHostPortPair())) |
| 5141 | ->IdleSocketCount()); |
| 5142 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5143 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5144 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5145 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5146 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5147 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5148 | ProxyHostPortPair())) |
| 5149 | ->IdleSocketCount()); |
| 5150 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5151 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5152 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5153 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5154 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5155 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5156 | ProxyHostPortPair())) |
| 5157 | ->IdleSocketCount()); |
| 5158 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5159 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5160 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5161 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5162 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5163 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5164 | ProxyHostPortPair(), |
| 5165 | true /* is_trusted_proxy */)) |
| 5166 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5167 | } |
| 5168 | } |
| 5169 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5170 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5171 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5172 | HttpRequestInfo request1; |
| 5173 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5174 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5175 | request1.traffic_annotation = |
| 5176 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5177 | |
| 5178 | HttpRequestInfo request2; |
| 5179 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5180 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5181 | request2.traffic_annotation = |
| 5182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5183 | |
| 5184 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5185 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5186 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5187 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5188 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5190 | |
| 5191 | // Since we have proxy, should try to establish tunnel. |
| 5192 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5193 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5194 | "Host: www.example.org:443\r\n" |
| 5195 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5196 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5197 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5198 | "Host: www.example.org\r\n" |
| 5199 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5200 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5201 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5202 | "Host: www.example.org\r\n" |
| 5203 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5204 | }; |
| 5205 | |
| 5206 | // The proxy responds to the connect with a 407, using a persistent |
| 5207 | // connection. |
| 5208 | MockRead data_reads1[] = { |
| 5209 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5210 | |
| 5211 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5212 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5213 | MockRead(SYNCHRONOUS, "1"), |
| 5214 | |
| 5215 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5216 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5217 | MockRead(SYNCHRONOUS, "22"), |
| 5218 | }; |
| 5219 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5220 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5221 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5222 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5224 | |
| 5225 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5226 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5227 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5228 | |
| 5229 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5234 | |
| 5235 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5236 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5237 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5238 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5239 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5240 | |
| 5241 | LoadTimingInfo load_timing_info1; |
| 5242 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5243 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5244 | |
| 5245 | trans1.reset(); |
| 5246 | |
| 5247 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5248 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5249 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5250 | |
| 5251 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5253 | |
| 5254 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5255 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5256 | |
| 5257 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5258 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5259 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5260 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5261 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5262 | |
| 5263 | LoadTimingInfo load_timing_info2; |
| 5264 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5265 | TestLoadTimingReused(load_timing_info2); |
| 5266 | |
| 5267 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5268 | |
| 5269 | trans2.reset(); |
| 5270 | session->CloseAllConnections(); |
| 5271 | } |
| 5272 | |
| 5273 | // 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] | 5274 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5275 | HttpRequestInfo request1; |
| 5276 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5277 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5278 | request1.traffic_annotation = |
| 5279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5280 | |
| 5281 | HttpRequestInfo request2; |
| 5282 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5283 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5284 | request2.traffic_annotation = |
| 5285 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5286 | |
| 5287 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5288 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5289 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5290 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5291 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5292 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5294 | |
| 5295 | // Since we have proxy, should try to establish tunnel. |
| 5296 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5297 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5298 | "Host: www.example.org:443\r\n" |
| 5299 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5300 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5301 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5302 | "Host: www.example.org\r\n" |
| 5303 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5304 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5305 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5306 | "Host: www.example.org\r\n" |
| 5307 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5308 | }; |
| 5309 | |
| 5310 | // The proxy responds to the connect with a 407, using a persistent |
| 5311 | // connection. |
| 5312 | MockRead data_reads1[] = { |
| 5313 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5314 | |
| 5315 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5316 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5317 | MockRead(SYNCHRONOUS, "1"), |
| 5318 | |
| 5319 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5320 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5321 | MockRead(SYNCHRONOUS, "22"), |
| 5322 | }; |
| 5323 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5324 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5326 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5328 | |
| 5329 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5330 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5331 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5332 | |
| 5333 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5338 | |
| 5339 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5340 | ASSERT_TRUE(response1); |
| 5341 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5342 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5343 | |
| 5344 | LoadTimingInfo load_timing_info1; |
| 5345 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5346 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5347 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5348 | |
| 5349 | trans1.reset(); |
| 5350 | |
| 5351 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5352 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5353 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5354 | |
| 5355 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5357 | |
| 5358 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5360 | |
| 5361 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5362 | ASSERT_TRUE(response2); |
| 5363 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5364 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5365 | |
| 5366 | LoadTimingInfo load_timing_info2; |
| 5367 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5368 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5369 | |
| 5370 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5371 | |
| 5372 | trans2.reset(); |
| 5373 | session->CloseAllConnections(); |
| 5374 | } |
| 5375 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5376 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5377 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5378 | HttpRequestInfo request; |
| 5379 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5380 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5381 | request.traffic_annotation = |
| 5382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5383 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5384 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5385 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5386 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5387 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5388 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5389 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5390 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5391 | // Since we have proxy, should use full url |
| 5392 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5393 | MockWrite( |
| 5394 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5395 | "Host: www.example.org\r\n" |
| 5396 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5397 | }; |
| 5398 | |
| 5399 | MockRead data_reads1[] = { |
| 5400 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5402 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5403 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5404 | }; |
| 5405 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5406 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5408 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5410 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5411 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5415 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5416 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5417 | |
| 5418 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5419 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5421 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5422 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5423 | TestLoadTimingNotReused(load_timing_info, |
| 5424 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5425 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5426 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5427 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5429 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5430 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5431 | EXPECT_EQ(200, response->headers->response_code()); |
| 5432 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5433 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5434 | |
| 5435 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5436 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5437 | } |
| 5438 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5439 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5440 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5441 | HttpRequestInfo request; |
| 5442 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5443 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5444 | request.traffic_annotation = |
| 5445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5446 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5447 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5448 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5449 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5450 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5451 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5452 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5453 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5454 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5455 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5456 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5457 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5458 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5459 | spdy::SpdySerializedFrame resp( |
| 5460 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5461 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5462 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5463 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5464 | }; |
| 5465 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5466 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5467 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5468 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5469 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5470 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5473 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5477 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5479 | |
| 5480 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5481 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5482 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5483 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5484 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5485 | TestLoadTimingNotReused(load_timing_info, |
| 5486 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5489 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5490 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5491 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5492 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5493 | |
| 5494 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5495 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5496 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5497 | } |
| 5498 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5499 | // Verifies that a session which races and wins against the owning transaction |
| 5500 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5501 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5502 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5503 | HttpRequestInfo request; |
| 5504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5505 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5506 | request.traffic_annotation = |
| 5507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5508 | |
| 5509 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5510 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5511 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5512 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5513 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5515 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5516 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5517 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5518 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5519 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5520 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5521 | spdy::SpdySerializedFrame resp( |
| 5522 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5523 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5524 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5525 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5526 | }; |
| 5527 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5528 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5529 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5530 | |
| 5531 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5532 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5534 | |
| 5535 | TestCompletionCallback callback1; |
| 5536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5538 | |
| 5539 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5540 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5542 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5544 | |
| 5545 | // Race a session to the proxy, which completes first. |
| 5546 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5547 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5548 | PRIVACY_MODE_DISABLED, |
| 5549 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5550 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5551 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5552 | |
| 5553 | // Unstall the resolution begun by the transaction. |
| 5554 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5555 | session_deps_.host_resolver->ResolveAllPending(); |
| 5556 | |
| 5557 | EXPECT_FALSE(callback1.have_result()); |
| 5558 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5562 | ASSERT_TRUE(response); |
| 5563 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5564 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5565 | |
| 5566 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5567 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5568 | EXPECT_EQ(kUploadData, response_data); |
| 5569 | } |
| 5570 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5571 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5572 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5573 | HttpRequestInfo request; |
| 5574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5575 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5576 | request.traffic_annotation = |
| 5577 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5578 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5579 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5580 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5581 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5582 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5583 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5585 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5586 | // The first request will be a bare GET, the second request will be a |
| 5587 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5588 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5589 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5590 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5591 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5592 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5593 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5594 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5595 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5596 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5597 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5598 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5599 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5600 | }; |
| 5601 | |
| 5602 | // The first response is a 407 proxy authentication challenge, and the second |
| 5603 | // response will be a 200 response since the second request includes a valid |
| 5604 | // Authorization header. |
| 5605 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5606 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5607 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5608 | spdy::SpdySerializedFrame resp_authentication( |
| 5609 | spdy_util_.ConstructSpdyReplyError( |
| 5610 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5611 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5612 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5613 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5614 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5615 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5616 | spdy::SpdySerializedFrame body_data( |
| 5617 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5618 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5619 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5620 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5621 | CreateMockRead(resp_data, 4), |
| 5622 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5623 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | }; |
| 5625 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5626 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5628 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5629 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5630 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5633 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5634 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5637 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5639 | |
| 5640 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5641 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5643 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5644 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5645 | ASSERT_TRUE(response); |
| 5646 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5647 | EXPECT_EQ(407, response->headers->response_code()); |
| 5648 | EXPECT_TRUE(response->was_fetched_via_spdy); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5649 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5651 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5653 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5655 | |
| 5656 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5657 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5659 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5660 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5661 | ASSERT_TRUE(response_restart); |
| 5662 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5663 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5664 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5665 | EXPECT_FALSE(response_restart->auth_challenge.has_value()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5666 | } |
| 5667 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5668 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5669 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5670 | HttpRequestInfo request; |
| 5671 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5672 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5673 | request.traffic_annotation = |
| 5674 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5675 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5676 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5677 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5678 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5679 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5680 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5684 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5685 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5686 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5687 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5688 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5689 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5690 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5691 | const char get[] = |
| 5692 | "GET / HTTP/1.1\r\n" |
| 5693 | "Host: www.example.org\r\n" |
| 5694 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5695 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5696 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5697 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5698 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5699 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5700 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5701 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5702 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5703 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5704 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5705 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5706 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5707 | |
| 5708 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5709 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5710 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5711 | }; |
| 5712 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5713 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5714 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5715 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5716 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5717 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5718 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5719 | }; |
| 5720 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5721 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5722 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5723 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5724 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5725 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5727 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5730 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5732 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5734 | |
| 5735 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5736 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5737 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5738 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5739 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5740 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5743 | ASSERT_TRUE(response); |
| 5744 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5745 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5746 | |
| 5747 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5748 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5749 | EXPECT_EQ("1234567890", response_data); |
| 5750 | } |
| 5751 | |
| 5752 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5753 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5754 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5755 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5756 | HttpRequestInfo request; |
| 5757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5758 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5759 | request.traffic_annotation = |
| 5760 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5761 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5762 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5763 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5764 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5765 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5766 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5770 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5771 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5772 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5773 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5774 | HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5775 | // fetch https://www.example.org/ via SPDY |
| 5776 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5777 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5778 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5779 | spdy::SpdySerializedFrame wrapped_get( |
| 5780 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5781 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5782 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5783 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5784 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5785 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5786 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5787 | spdy::SpdySerializedFrame body( |
| 5788 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5789 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5790 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5791 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5792 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5793 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5795 | |
| 5796 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5797 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5798 | CreateMockWrite(window_update_get_resp, 6), |
| 5799 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5800 | }; |
| 5801 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5802 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5803 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5804 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5805 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5806 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5807 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5808 | }; |
| 5809 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5810 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5811 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5812 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5813 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5814 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5815 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5816 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5817 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5820 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5822 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5824 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5825 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5826 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5827 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5828 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5829 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5831 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5832 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5834 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5836 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5837 | ASSERT_TRUE(response); |
| 5838 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5839 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5840 | |
| 5841 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5842 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5843 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5844 | } |
| 5845 | |
| 5846 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5847 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5848 | HttpRequestInfo request; |
| 5849 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5850 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5851 | request.traffic_annotation = |
| 5852 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5853 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5854 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5855 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5856 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5857 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5858 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5862 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5863 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5864 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 5865 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 5866 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5867 | spdy::SpdySerializedFrame get( |
| 5868 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | |
| 5870 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5871 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5872 | }; |
| 5873 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5874 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5875 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5877 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5878 | }; |
| 5879 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5880 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5881 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5882 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5883 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5884 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5885 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5886 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5887 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5888 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5890 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5892 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5894 | |
| 5895 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5896 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5897 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5898 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5899 | } |
| 5900 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5901 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5902 | // is observed, but does exist by the time auth credentials are provided. |
| 5903 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5904 | // what causes the existing H2 session to be noticed and reused. |
| 5905 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5906 | ProxyConfig proxy_config; |
| 5907 | proxy_config.set_auto_detect(true); |
| 5908 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5909 | |
| 5910 | CapturingProxyResolver capturing_proxy_resolver; |
| 5911 | capturing_proxy_resolver.set_proxy_server( |
| 5912 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5913 | session_deps_.proxy_resolution_service = |
| 5914 | std::make_unique<ProxyResolutionService>( |
| 5915 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5916 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5917 | std::make_unique<CapturingProxyResolverFactory>( |
| 5918 | &capturing_proxy_resolver), |
| 5919 | nullptr); |
| 5920 | |
| 5921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5922 | |
| 5923 | const char kMyUrl[] = "https://www.example.org/"; |
| 5924 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5925 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5926 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5927 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5928 | |
| 5929 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5930 | spdy::SpdySerializedFrame get2( |
| 5931 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5932 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 5933 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5934 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5935 | |
| 5936 | MockWrite auth_challenge_writes[] = { |
| 5937 | MockWrite(ASYNC, 0, |
| 5938 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5939 | "Host: www.example.org:443\r\n" |
| 5940 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5941 | }; |
| 5942 | |
| 5943 | MockRead auth_challenge_reads[] = { |
| 5944 | MockRead(ASYNC, 1, |
| 5945 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5946 | "Content-Length: 0\r\n" |
| 5947 | "Proxy-Connection: close\r\n" |
| 5948 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5949 | }; |
| 5950 | |
| 5951 | MockWrite spdy_writes[] = { |
| 5952 | MockWrite(ASYNC, 0, |
| 5953 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5954 | "Host: www.example.org:443\r\n" |
| 5955 | "Proxy-Connection: keep-alive\r\n" |
| 5956 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5957 | CreateMockWrite(get, 2), |
| 5958 | CreateMockWrite(get2, 5), |
| 5959 | }; |
| 5960 | |
| 5961 | MockRead spdy_reads[] = { |
| 5962 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5963 | CreateMockRead(get_resp, 3, ASYNC), |
| 5964 | CreateMockRead(body, 4, ASYNC), |
| 5965 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5966 | CreateMockRead(body2, 7, ASYNC), |
| 5967 | |
| 5968 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5969 | }; |
| 5970 | |
| 5971 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5972 | auth_challenge_writes); |
| 5973 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5974 | |
| 5975 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5976 | auth_challenge_writes); |
| 5977 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5978 | |
| 5979 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5980 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5981 | |
| 5982 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5983 | ssl.next_proto = kProtoHTTP2; |
| 5984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5985 | |
| 5986 | TestCompletionCallback callback; |
| 5987 | std::string response_data; |
| 5988 | |
| 5989 | // Run first request until an auth challenge is observed. |
| 5990 | HttpRequestInfo request1; |
| 5991 | request1.method = "GET"; |
| 5992 | request1.url = GURL(kMyUrl); |
| 5993 | request1.traffic_annotation = |
| 5994 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5995 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5996 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5997 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5998 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5999 | ASSERT_TRUE(response); |
| 6000 | ASSERT_TRUE(response->headers); |
| 6001 | EXPECT_EQ(407, response->headers->response_code()); |
| 6002 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6003 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6004 | |
| 6005 | // Run second request until an auth challenge is observed. |
| 6006 | HttpRequestInfo request2; |
| 6007 | request2.method = "GET"; |
| 6008 | request2.url = GURL(kMyUrl); |
| 6009 | request2.traffic_annotation = |
| 6010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6011 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6012 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6013 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6014 | response = trans2.GetResponseInfo(); |
| 6015 | ASSERT_TRUE(response); |
| 6016 | ASSERT_TRUE(response->headers); |
| 6017 | EXPECT_EQ(407, response->headers->response_code()); |
| 6018 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6019 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 6020 | |
| 6021 | // Now provide credentials for the first request, and wait for it to complete. |
| 6022 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6023 | rv = callback.GetResult(rv); |
| 6024 | EXPECT_THAT(rv, IsOk()); |
| 6025 | response = trans1.GetResponseInfo(); |
| 6026 | ASSERT_TRUE(response); |
| 6027 | ASSERT_TRUE(response->headers); |
| 6028 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6029 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6030 | EXPECT_EQ(kUploadData, response_data); |
| 6031 | |
| 6032 | // Now provide credentials for the second request. It should notice the |
| 6033 | // existing session, and reuse it. |
| 6034 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6035 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6036 | response = trans2.GetResponseInfo(); |
| 6037 | ASSERT_TRUE(response); |
| 6038 | ASSERT_TRUE(response->headers); |
| 6039 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6040 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6041 | EXPECT_EQ(kUploadData, response_data); |
| 6042 | } |
| 6043 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6044 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6045 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6046 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6047 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6048 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6049 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6050 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6051 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6052 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6053 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6054 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6055 | |
| 6056 | HttpRequestInfo request1; |
| 6057 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6058 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6059 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6060 | request1.traffic_annotation = |
| 6061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6062 | |
| 6063 | HttpRequestInfo request2; |
| 6064 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6065 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6066 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6067 | request2.traffic_annotation = |
| 6068 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6069 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6070 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6071 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6072 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6073 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6074 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6075 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6076 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6077 | // Fetch https://www.example.org/ via HTTP. |
| 6078 | const char get1[] = |
| 6079 | "GET / HTTP/1.1\r\n" |
| 6080 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6081 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6082 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6083 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6084 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6085 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6086 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6087 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6088 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6089 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6090 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6091 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6092 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6093 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6094 | spdy::SpdyHeaderBlock connect2_block; |
| 6095 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6096 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6097 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6098 | 3, std::move(connect2_block), HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6099 | false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6100 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6101 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6102 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6103 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6104 | // Fetch https://mail.example.org/ via HTTP. |
| 6105 | const char get2[] = |
| 6106 | "GET / HTTP/1.1\r\n" |
| 6107 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6108 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6109 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6110 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6111 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6112 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6113 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6114 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6115 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6116 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6117 | |
| 6118 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6119 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6120 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6121 | }; |
| 6122 | |
| 6123 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6124 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6125 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6126 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6127 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6128 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6129 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6130 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6131 | }; |
| 6132 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6133 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6134 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6135 | |
| 6136 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6137 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6138 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6139 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6141 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6143 | |
| 6144 | TestCompletionCallback callback; |
| 6145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6147 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6148 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6149 | |
| 6150 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6151 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6152 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6155 | ASSERT_TRUE(response); |
| 6156 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6157 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6158 | |
| 6159 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6160 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6162 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6164 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6165 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6166 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6167 | |
| 6168 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6169 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6170 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6171 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6172 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6173 | |
| 6174 | // The requests should have different IDs, since they each are using their own |
| 6175 | // separate stream. |
| 6176 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6178 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6179 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6183 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6184 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6186 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6187 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6188 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6189 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6190 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6191 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6192 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6193 | |
| 6194 | HttpRequestInfo request1; |
| 6195 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6196 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6197 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6198 | request1.traffic_annotation = |
| 6199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6200 | |
| 6201 | HttpRequestInfo request2; |
| 6202 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6203 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6205 | request2.traffic_annotation = |
| 6206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6207 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6208 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6209 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6210 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6211 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6212 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6213 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6214 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6215 | // Fetch https://www.example.org/ via HTTP. |
| 6216 | const char get1[] = |
| 6217 | "GET / HTTP/1.1\r\n" |
| 6218 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6220 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6221 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6222 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6223 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6224 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6225 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6226 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6227 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6228 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6229 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6230 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6231 | // Fetch https://www.example.org/2 via HTTP. |
| 6232 | const char get2[] = |
| 6233 | "GET /2 HTTP/1.1\r\n" |
| 6234 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6235 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6236 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6237 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6238 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6239 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6240 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6241 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6242 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6243 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6244 | |
| 6245 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6246 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6247 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | }; |
| 6249 | |
| 6250 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6251 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6252 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6253 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6254 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6255 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6256 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6257 | }; |
| 6258 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6259 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6260 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6261 | |
| 6262 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6263 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6265 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6267 | |
| 6268 | TestCompletionCallback callback; |
| 6269 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6270 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6271 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6272 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6274 | |
| 6275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6277 | |
| 6278 | LoadTimingInfo load_timing_info; |
| 6279 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6280 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6281 | |
| 6282 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6283 | ASSERT_TRUE(response); |
| 6284 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6285 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6286 | |
| 6287 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6288 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6289 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6290 | trans.reset(); |
| 6291 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6292 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6293 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6294 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6296 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6297 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6298 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6299 | |
| 6300 | LoadTimingInfo load_timing_info2; |
| 6301 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6302 | TestLoadTimingReused(load_timing_info2); |
| 6303 | |
| 6304 | // The requests should have the same ID. |
| 6305 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6306 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6307 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6308 | } |
| 6309 | |
| 6310 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6311 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6312 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6313 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6314 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6315 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6316 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6317 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6318 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6319 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6320 | |
| 6321 | HttpRequestInfo request1; |
| 6322 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6323 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6324 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6325 | request1.traffic_annotation = |
| 6326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6327 | |
| 6328 | HttpRequestInfo request2; |
| 6329 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6330 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6331 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6332 | request2.traffic_annotation = |
| 6333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6335 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6336 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6338 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6339 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6340 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6341 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6342 | spdy::SpdySerializedFrame body1( |
| 6343 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6344 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6345 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6346 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6347 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6348 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6349 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6350 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6351 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6352 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6353 | spdy::SpdySerializedFrame body2( |
| 6354 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6355 | |
| 6356 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6357 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6358 | }; |
| 6359 | |
| 6360 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6361 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6362 | CreateMockRead(body1, 2, ASYNC), |
| 6363 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6364 | CreateMockRead(body2, 5, ASYNC), |
| 6365 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6366 | }; |
| 6367 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6368 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6369 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6370 | |
| 6371 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6372 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6373 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6374 | |
| 6375 | TestCompletionCallback callback; |
| 6376 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6377 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6378 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6379 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6380 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6381 | |
| 6382 | LoadTimingInfo load_timing_info; |
| 6383 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6384 | TestLoadTimingNotReused(load_timing_info, |
| 6385 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6386 | |
| 6387 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6388 | ASSERT_TRUE(response); |
| 6389 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6390 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6391 | |
| 6392 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6393 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6394 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6395 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6396 | // Delete the first request, so the second one can reuse the socket. |
| 6397 | trans.reset(); |
| 6398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6399 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6400 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6401 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6402 | |
| 6403 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6404 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6405 | TestLoadTimingReused(load_timing_info2); |
| 6406 | |
| 6407 | // The requests should have the same ID. |
| 6408 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6410 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6411 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6412 | } |
| 6413 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6414 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6415 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6416 | // would break socket pool isolation. |
| 6417 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6418 | ProxyConfig proxy_config; |
| 6419 | proxy_config.set_auto_detect(true); |
| 6420 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6421 | |
| 6422 | CapturingProxyResolver capturing_proxy_resolver; |
| 6423 | session_deps_.proxy_resolution_service = |
| 6424 | std::make_unique<ProxyResolutionService>( |
| 6425 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6426 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6427 | std::make_unique<CapturingProxyResolverFactory>( |
| 6428 | &capturing_proxy_resolver), |
| 6429 | nullptr); |
| 6430 | |
| 6431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6432 | |
| 6433 | SpdyTestUtil spdy_util1; |
| 6434 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6435 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6436 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6437 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6438 | // fetch https://www.example.org/ via HTTP/2. |
| 6439 | const char kMyUrl[] = "https://www.example.org/"; |
| 6440 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6441 | spdy::SpdySerializedFrame wrapped_get( |
| 6442 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6443 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6444 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6445 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 6446 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6447 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6448 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6449 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6450 | spdy::SpdySerializedFrame wrapped_body( |
| 6451 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6452 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6453 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6454 | spdy::SpdySerializedFrame window_update_body( |
| 6455 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6456 | |
| 6457 | MockWrite spdy_writes1[] = { |
| 6458 | CreateMockWrite(connect, 0), |
| 6459 | CreateMockWrite(wrapped_get, 2), |
| 6460 | CreateMockWrite(window_update_get_resp, 6), |
| 6461 | CreateMockWrite(window_update_body, 7), |
| 6462 | }; |
| 6463 | |
| 6464 | MockRead spdy_reads1[] = { |
| 6465 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6466 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6467 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6468 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6469 | MockRead(ASYNC, 0, 8), |
| 6470 | }; |
| 6471 | |
| 6472 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6473 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6474 | |
| 6475 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6476 | // a new pipe. |
| 6477 | SpdyTestUtil spdy_util2; |
| 6478 | spdy::SpdySerializedFrame req( |
| 6479 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6480 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6481 | |
| 6482 | spdy::SpdySerializedFrame resp( |
| 6483 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6484 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6485 | MockRead spdy_reads2[] = { |
| 6486 | CreateMockRead(resp, 1), |
| 6487 | CreateMockRead(data, 2), |
| 6488 | MockRead(ASYNC, 0, 3), |
| 6489 | }; |
| 6490 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6491 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6492 | |
| 6493 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6494 | ssl.next_proto = kProtoHTTP2; |
| 6495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6496 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6497 | ssl2.next_proto = kProtoHTTP2; |
| 6498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6499 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6500 | ssl3.next_proto = kProtoHTTP2; |
| 6501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6502 | |
| 6503 | TestCompletionCallback callback; |
| 6504 | std::string response_data; |
| 6505 | |
| 6506 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6507 | capturing_proxy_resolver.set_proxy_server( |
| 6508 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6509 | HttpRequestInfo request1; |
| 6510 | request1.method = "GET"; |
| 6511 | request1.url = GURL("https://www.example.org/"); |
| 6512 | request1.traffic_annotation = |
| 6513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6514 | |
| 6515 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6516 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6518 | |
| 6519 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6520 | base::RunLoop().RunUntilIdle(); |
| 6521 | // Now allow the read of the response to complete. |
| 6522 | spdy_data1.Resume(); |
| 6523 | rv = callback.WaitForResult(); |
| 6524 | EXPECT_THAT(rv, IsOk()); |
| 6525 | |
| 6526 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6527 | ASSERT_TRUE(response); |
| 6528 | ASSERT_TRUE(response->headers); |
| 6529 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6530 | |
| 6531 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6532 | EXPECT_EQ(kUploadData, response_data); |
| 6533 | RunUntilIdle(); |
| 6534 | |
| 6535 | // Make a direct HTTP/2 request to proxy:70. |
| 6536 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6537 | HttpRequestInfo request2; |
| 6538 | request2.method = "GET"; |
| 6539 | request2.url = GURL("https://proxy:70/"); |
| 6540 | request2.traffic_annotation = |
| 6541 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6542 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6543 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6544 | NetLogWithSource())), |
| 6545 | IsOk()); |
| 6546 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6547 | } |
| 6548 | |
| 6549 | // Same as above, but reverse request order, since the code to check for an |
| 6550 | // existing session is different for tunnels and direct connections. |
| 6551 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6552 | // Configure against https proxy server "myproxy:80". |
| 6553 | ProxyConfig proxy_config; |
| 6554 | proxy_config.set_auto_detect(true); |
| 6555 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6556 | |
| 6557 | CapturingProxyResolver capturing_proxy_resolver; |
| 6558 | session_deps_.proxy_resolution_service = |
| 6559 | std::make_unique<ProxyResolutionService>( |
| 6560 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6561 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6562 | std::make_unique<CapturingProxyResolverFactory>( |
| 6563 | &capturing_proxy_resolver), |
| 6564 | nullptr); |
| 6565 | |
| 6566 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6567 | // Fetch https://proxy:70/ via HTTP/2. |
| 6568 | SpdyTestUtil spdy_util1; |
| 6569 | spdy::SpdySerializedFrame req( |
| 6570 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6571 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6572 | |
| 6573 | spdy::SpdySerializedFrame resp( |
| 6574 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6575 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6576 | MockRead spdy_reads1[] = { |
| 6577 | CreateMockRead(resp, 1), |
| 6578 | CreateMockRead(data, 2), |
| 6579 | MockRead(ASYNC, 0, 3), |
| 6580 | }; |
| 6581 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6582 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6583 | |
| 6584 | SpdyTestUtil spdy_util2; |
| 6585 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6586 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 6587 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 6588 | HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6589 | // fetch https://www.example.org/ via HTTP/2. |
| 6590 | const char kMyUrl[] = "https://www.example.org/"; |
| 6591 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6592 | spdy::SpdySerializedFrame wrapped_get( |
| 6593 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6594 | spdy::SpdySerializedFrame conn_resp( |
| 6595 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6596 | spdy::SpdySerializedFrame get_resp( |
| 6597 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6598 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6599 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6600 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6601 | spdy::SpdySerializedFrame wrapped_body( |
| 6602 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6603 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6604 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6605 | spdy::SpdySerializedFrame window_update_body( |
| 6606 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6607 | |
| 6608 | MockWrite spdy_writes2[] = { |
| 6609 | CreateMockWrite(connect, 0), |
| 6610 | CreateMockWrite(wrapped_get, 2), |
| 6611 | CreateMockWrite(window_update_get_resp, 6), |
| 6612 | CreateMockWrite(window_update_body, 7), |
| 6613 | }; |
| 6614 | |
| 6615 | MockRead spdy_reads2[] = { |
| 6616 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6617 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6618 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6619 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6620 | MockRead(ASYNC, 0, 8), |
| 6621 | }; |
| 6622 | |
| 6623 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6624 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6625 | |
| 6626 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6627 | ssl.next_proto = kProtoHTTP2; |
| 6628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6629 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6630 | ssl2.next_proto = kProtoHTTP2; |
| 6631 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6632 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6633 | ssl3.next_proto = kProtoHTTP2; |
| 6634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6635 | |
| 6636 | TestCompletionCallback callback; |
| 6637 | std::string response_data; |
| 6638 | |
| 6639 | // Make a direct HTTP/2 request to proxy:70. |
| 6640 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6641 | HttpRequestInfo request1; |
| 6642 | request1.method = "GET"; |
| 6643 | request1.url = GURL("https://proxy:70/"); |
| 6644 | request1.traffic_annotation = |
| 6645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6646 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6647 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6648 | NetLogWithSource())), |
| 6649 | IsOk()); |
| 6650 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6651 | RunUntilIdle(); |
| 6652 | |
| 6653 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6654 | capturing_proxy_resolver.set_proxy_server( |
| 6655 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6656 | HttpRequestInfo request2; |
| 6657 | request2.method = "GET"; |
| 6658 | request2.url = GURL("https://www.example.org/"); |
| 6659 | request2.traffic_annotation = |
| 6660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6661 | |
| 6662 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6663 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6665 | |
| 6666 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6667 | base::RunLoop().RunUntilIdle(); |
| 6668 | // Now allow the read of the response to complete. |
| 6669 | spdy_data2.Resume(); |
| 6670 | rv = callback.WaitForResult(); |
| 6671 | EXPECT_THAT(rv, IsOk()); |
| 6672 | |
| 6673 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6674 | ASSERT_TRUE(response2); |
| 6675 | ASSERT_TRUE(response2->headers); |
| 6676 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6677 | |
| 6678 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6679 | EXPECT_EQ(kUploadData, response_data); |
| 6680 | } |
| 6681 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6682 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6683 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6684 | HttpRequestInfo request; |
| 6685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6686 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6687 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6688 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6689 | request.traffic_annotation = |
| 6690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6691 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6692 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6693 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6694 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6695 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6696 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6698 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6699 | // Since we have proxy, should use full url |
| 6700 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6701 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6702 | "Host: www.example.org\r\n" |
| 6703 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6705 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6706 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6707 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6708 | "Host: www.example.org\r\n" |
| 6709 | "Proxy-Connection: keep-alive\r\n" |
| 6710 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | }; |
| 6712 | |
| 6713 | // The proxy responds to the GET with a 407, using a persistent |
| 6714 | // connection. |
| 6715 | MockRead data_reads1[] = { |
| 6716 | // No credentials. |
| 6717 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6718 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6719 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6720 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6721 | |
| 6722 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6723 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6724 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6725 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6726 | }; |
| 6727 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6728 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6729 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6730 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6733 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6737 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6739 | |
| 6740 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6742 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6743 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6744 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6745 | TestLoadTimingNotReused(load_timing_info, |
| 6746 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6749 | ASSERT_TRUE(response); |
| 6750 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6751 | EXPECT_EQ(407, response->headers->response_code()); |
| 6752 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6753 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6754 | EXPECT_FALSE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6756 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6758 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6760 | |
| 6761 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6763 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6764 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6765 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6766 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6767 | TestLoadTimingReused(load_timing_info); |
| 6768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6769 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6770 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6771 | |
| 6772 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6773 | EXPECT_EQ(200, response->headers->response_code()); |
| 6774 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6775 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Wojciech Dzierżanowski | 0950c37 | 2019-04-02 19:29:50 | [diff] [blame] | 6776 | EXPECT_TRUE(response->did_use_http_auth); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6777 | |
| 6778 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 6779 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6780 | } |
| 6781 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6782 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6783 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6784 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6785 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6786 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6787 | request.traffic_annotation = |
| 6788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6789 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6790 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6791 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6792 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6794 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6795 | // Since we have proxy, should try to establish tunnel. |
| 6796 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6797 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6798 | "Host: www.example.org:443\r\n" |
| 6799 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6800 | }; |
| 6801 | |
| 6802 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6803 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6804 | // No response body because the test stops reading here. |
| 6805 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6806 | }; |
| 6807 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6808 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6809 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6815 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | |
| 6818 | rv = callback.WaitForResult(); |
| 6819 | EXPECT_EQ(expected_status, rv); |
| 6820 | } |
| 6821 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6822 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6823 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6825 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6826 | } |
| 6827 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6828 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6829 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6830 | } |
| 6831 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6832 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6833 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6834 | } |
| 6835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6836 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6837 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper( |
| 6846 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6847 | } |
| 6848 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6849 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6850 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6851 | } |
| 6852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6853 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6854 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6855 | } |
| 6856 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6857 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6858 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6859 | } |
| 6860 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6861 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6862 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6863 | } |
| 6864 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6865 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6866 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6867 | } |
| 6868 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6869 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6870 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6871 | } |
| 6872 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6873 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6874 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6875 | } |
| 6876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6877 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6878 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6879 | } |
| 6880 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6881 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6882 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6883 | } |
| 6884 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6885 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6886 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6887 | } |
| 6888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6889 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6890 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6891 | } |
| 6892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6893 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6894 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6895 | } |
| 6896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6897 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6898 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6899 | } |
| 6900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6901 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6902 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6903 | } |
| 6904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6905 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6906 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6907 | } |
| 6908 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6909 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6910 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6911 | } |
| 6912 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6913 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6914 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6915 | } |
| 6916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6917 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6918 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6919 | } |
| 6920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6921 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6922 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6923 | } |
| 6924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6925 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6926 | ConnectStatusHelperWithExpectedStatus( |
| 6927 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6928 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6929 | } |
| 6930 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6931 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6932 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6933 | } |
| 6934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6935 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6936 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6937 | } |
| 6938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6939 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6940 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6941 | } |
| 6942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6943 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6944 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6945 | } |
| 6946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6947 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6948 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6949 | } |
| 6950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6951 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6952 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6961 | } |
| 6962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6964 | ConnectStatusHelper( |
| 6965 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6966 | } |
| 6967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6968 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6969 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6970 | } |
| 6971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6972 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6973 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6974 | } |
| 6975 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6976 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6977 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6978 | } |
| 6979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6980 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6981 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6982 | } |
| 6983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6984 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6985 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6986 | } |
| 6987 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6988 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6989 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6990 | } |
| 6991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6992 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6993 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6994 | } |
| 6995 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6996 | // Test the flow when both the proxy server AND origin server require |
| 6997 | // authentication. Again, this uses basic auth for both since that is |
| 6998 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6999 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7000 | HttpRequestInfo request; |
| 7001 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7002 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7003 | request.traffic_annotation = |
| 7004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7005 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7006 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7007 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7008 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 7010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7011 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7012 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7013 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7014 | MockWrite( |
| 7015 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7016 | "Host: www.example.org\r\n" |
| 7017 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7018 | }; |
| 7019 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7020 | MockRead data_reads1[] = { |
| 7021 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7022 | // Give a couple authenticate options (only the middle one is actually |
| 7023 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7024 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7025 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7026 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7027 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7028 | // Large content-length -- won't matter, as connection will be reset. |
| 7029 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7030 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7031 | }; |
| 7032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7033 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7034 | // request we should be issuing -- the final header line contains the |
| 7035 | // proxy's credentials. |
| 7036 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7037 | MockWrite( |
| 7038 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7039 | "Host: www.example.org\r\n" |
| 7040 | "Proxy-Connection: keep-alive\r\n" |
| 7041 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7042 | }; |
| 7043 | |
| 7044 | // Now the proxy server lets the request pass through to origin server. |
| 7045 | // The origin server responds with a 401. |
| 7046 | MockRead data_reads2[] = { |
| 7047 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7048 | // Note: We are using the same realm-name as the proxy server. This is |
| 7049 | // completely valid, as realms are unique across hosts. |
| 7050 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7051 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7052 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7053 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7054 | }; |
| 7055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7056 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7057 | // the credentials for both the proxy and origin server. |
| 7058 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7059 | MockWrite( |
| 7060 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7061 | "Host: www.example.org\r\n" |
| 7062 | "Proxy-Connection: keep-alive\r\n" |
| 7063 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7064 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7065 | }; |
| 7066 | |
| 7067 | // Lastly we get the desired content. |
| 7068 | MockRead data_reads3[] = { |
| 7069 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7070 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7071 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7073 | }; |
| 7074 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7075 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7076 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7077 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7078 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7079 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7080 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7082 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7083 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7084 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7086 | |
| 7087 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7088 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7090 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7091 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7092 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7094 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7095 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7096 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | |
| 7099 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7102 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7103 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7104 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7106 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7108 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7109 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7111 | |
| 7112 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7115 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7116 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7117 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7118 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7119 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7120 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7121 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7122 | // authorization headers. |
| 7123 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7124 | // The NTLM authentication unit tests are based on known test data from the |
| 7125 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7126 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7127 | // for the implementation and testing of the protocol. |
| 7128 | // |
| 7129 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7130 | |
| 7131 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7132 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7133 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7134 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7135 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7136 | request.traffic_annotation = |
| 7137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7138 | |
| 7139 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7140 | // to other auth schemes. |
| 7141 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7142 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7143 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7144 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7146 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7147 | // Generate the NTLM messages based on known test data. |
| 7148 | std::string negotiate_msg; |
| 7149 | std::string challenge_msg; |
| 7150 | std::string authenticate_msg; |
| 7151 | base::Base64Encode( |
| 7152 | base::StringPiece( |
| 7153 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7154 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7155 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7156 | base::Base64Encode( |
| 7157 | base::StringPiece( |
| 7158 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7159 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7160 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7161 | base::Base64Encode( |
| 7162 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7163 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7164 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7165 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7166 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7167 | &authenticate_msg); |
| 7168 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7169 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7170 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7171 | "Host: server\r\n" |
| 7172 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7173 | }; |
| 7174 | |
| 7175 | MockRead data_reads1[] = { |
| 7176 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7177 | // Negotiate and NTLM are often requested together. However, we only want |
| 7178 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7179 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7180 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7181 | MockRead("Connection: close\r\n"), |
| 7182 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7183 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7184 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7185 | }; |
| 7186 | |
| 7187 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7188 | // After restarting with a null identity, this is the |
| 7189 | // request we should be issuing -- the final header line contains a Type |
| 7190 | // 1 message. |
| 7191 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7192 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7193 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7194 | "Authorization: NTLM "), |
| 7195 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7196 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7197 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7198 | // (using correct credentials). The second request continues on the |
| 7199 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7200 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7201 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7202 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7203 | "Authorization: NTLM "), |
| 7204 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7205 | }; |
| 7206 | |
| 7207 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7208 | // The origin server responds with a Type 2 message. |
| 7209 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7210 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7211 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7212 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7213 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7214 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7215 | // Lastly we get the desired content. |
| 7216 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7217 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7218 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7219 | }; |
| 7220 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7221 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7222 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7223 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7224 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7225 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7226 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7228 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7231 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7234 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7235 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7237 | |
| 7238 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7239 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7241 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7243 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7244 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7245 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7247 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7248 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7249 | rv = trans.RestartWithAuth( |
| 7250 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7251 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7253 | |
| 7254 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7255 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7257 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7259 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7260 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7261 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7263 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7265 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7267 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7268 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7271 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7272 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7273 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7274 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7275 | |
| 7276 | std::string response_data; |
| 7277 | rv = ReadTransaction(&trans, &response_data); |
| 7278 | EXPECT_THAT(rv, IsOk()); |
| 7279 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7280 | |
| 7281 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7282 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7283 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7284 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7285 | } |
| 7286 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7287 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7288 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7289 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7290 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7291 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7292 | request.traffic_annotation = |
| 7293 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7294 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7295 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7296 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7298 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7299 | // Generate the NTLM messages based on known test data. |
| 7300 | std::string negotiate_msg; |
| 7301 | std::string challenge_msg; |
| 7302 | std::string authenticate_msg; |
| 7303 | base::Base64Encode( |
| 7304 | base::StringPiece( |
| 7305 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7306 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7307 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7308 | base::Base64Encode( |
| 7309 | base::StringPiece( |
| 7310 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7311 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7312 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7313 | base::Base64Encode( |
| 7314 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7315 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7316 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7317 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7318 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7319 | &authenticate_msg); |
| 7320 | |
| 7321 | // The authenticate message when |kWrongPassword| is sent. |
| 7322 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7323 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7324 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7325 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7326 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7327 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7328 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7329 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7330 | // Sanity check that it's the same length as the correct authenticate message |
| 7331 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7332 | ASSERT_EQ(authenticate_msg.length(), |
| 7333 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7334 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7335 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7336 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7337 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7338 | "Host: server\r\n" |
| 7339 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7340 | }; |
| 7341 | |
| 7342 | MockRead data_reads1[] = { |
| 7343 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7344 | // Negotiate and NTLM are often requested together. However, we only want |
| 7345 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7346 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7347 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7348 | MockRead("Connection: close\r\n"), |
| 7349 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7350 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7351 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7352 | }; |
| 7353 | |
| 7354 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7355 | // After restarting with a null identity, this is the |
| 7356 | // request we should be issuing -- the final header line contains a Type |
| 7357 | // 1 message. |
| 7358 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7359 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7360 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7361 | "Authorization: NTLM "), |
| 7362 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7363 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7364 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7365 | // (using incorrect credentials). The second request continues on the |
| 7366 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7367 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7368 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7369 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7370 | "Authorization: NTLM "), |
| 7371 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7372 | }; |
| 7373 | |
| 7374 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7375 | // The origin server responds with a Type 2 message. |
| 7376 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7377 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7378 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7379 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7380 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7381 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7382 | // Wrong password. |
| 7383 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7384 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7385 | MockRead("Content-Length: 42\r\n"), |
| 7386 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7387 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7388 | }; |
| 7389 | |
| 7390 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | // After restarting with a null identity, this is the |
| 7392 | // request we should be issuing -- the final header line contains a Type |
| 7393 | // 1 message. |
| 7394 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7395 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7396 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7397 | "Authorization: NTLM "), |
| 7398 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7400 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7401 | // (the credentials for the origin server). The second request continues |
| 7402 | // on the same connection. |
| 7403 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7404 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7405 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7406 | "Authorization: NTLM "), |
| 7407 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7408 | }; |
| 7409 | |
| 7410 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7411 | // The origin server responds with a Type 2 message. |
| 7412 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7413 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7414 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7415 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7416 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7417 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7418 | // Lastly we get the desired content. |
| 7419 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7420 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7421 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7422 | }; |
| 7423 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7424 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7425 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7426 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7428 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7429 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7430 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7431 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7433 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7435 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7438 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7442 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7444 | |
| 7445 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7448 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7449 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7450 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7451 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7452 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7454 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7455 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7456 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7457 | rv = trans.RestartWithAuth( |
| 7458 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7459 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7460 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7461 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7462 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7463 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7465 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7466 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7467 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7469 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7471 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7473 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7474 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7475 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7477 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7478 | |
| 7479 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7480 | rv = trans.RestartWithAuth( |
| 7481 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7482 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7484 | |
| 7485 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7488 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7490 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7491 | |
| 7492 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7493 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7495 | |
| 7496 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7499 | response = trans.GetResponseInfo(); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7500 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7501 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7502 | |
| 7503 | std::string response_data; |
| 7504 | rv = ReadTransaction(&trans, &response_data); |
| 7505 | EXPECT_THAT(rv, IsOk()); |
| 7506 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7507 | |
| 7508 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7509 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7510 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7511 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7512 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7513 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7514 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7515 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7516 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7517 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7518 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7519 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7520 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7521 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7522 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7523 | |
| 7524 | HttpRequestInfo request; |
| 7525 | request.method = "GET"; |
| 7526 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7527 | request.traffic_annotation = |
| 7528 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7529 | |
| 7530 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7531 | spdy::SpdyHeaderBlock request_headers0( |
| 7532 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7533 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7534 | 1, std::move(request_headers0), LOWEST, true)); |
| 7535 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7536 | spdy::SpdyHeaderBlock response_headers0; |
| 7537 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7538 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7539 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7540 | 1, std::move(response_headers0), true)); |
| 7541 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7542 | // Stream 1 is closed. |
| 7543 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7544 | |
| 7545 | // Generate the NTLM messages based on known test data. |
| 7546 | std::string negotiate_msg; |
| 7547 | std::string challenge_msg; |
| 7548 | std::string authenticate_msg; |
| 7549 | base::Base64Encode( |
| 7550 | base::StringPiece( |
| 7551 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7552 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7553 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7554 | base::Base64Encode( |
| 7555 | base::StringPiece( |
| 7556 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7557 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7558 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7559 | base::Base64Encode( |
| 7560 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7561 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7562 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7563 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7564 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7565 | &authenticate_msg); |
| 7566 | |
| 7567 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7568 | spdy::SpdyHeaderBlock request_headers1( |
| 7569 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7570 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7571 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7572 | 3, std::move(request_headers1), LOWEST, true)); |
| 7573 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7574 | spdy::SpdySerializedFrame rst( |
| 7575 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7576 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7577 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7578 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7579 | |
| 7580 | // Retry yet again using HTTP/1.1. |
| 7581 | MockWrite writes1[] = { |
| 7582 | // After restarting with a null identity, this is the |
| 7583 | // request we should be issuing -- the final header line contains a Type |
| 7584 | // 1 message. |
| 7585 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7586 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7587 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7588 | "Authorization: NTLM "), |
| 7589 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7590 | |
| 7591 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7592 | // (the credentials for the origin server). The second request continues |
| 7593 | // on the same connection. |
| 7594 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7595 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7596 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7597 | "Authorization: NTLM "), |
| 7598 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7599 | }; |
| 7600 | |
| 7601 | MockRead reads1[] = { |
| 7602 | // The origin server responds with a Type 2 message. |
| 7603 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7604 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7605 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7606 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7607 | MockRead("You are not authorized to view this page\r\n"), |
| 7608 | |
| 7609 | // Lastly we get the desired content. |
| 7610 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7611 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7612 | 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] | 7613 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7614 | SequencedSocketData data0(reads0, writes0); |
| 7615 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7616 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7617 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7618 | |
| 7619 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7620 | ssl0.next_proto = kProtoHTTP2; |
| 7621 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7624 | |
| 7625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7627 | |
| 7628 | TestCompletionCallback callback1; |
| 7629 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7631 | |
| 7632 | rv = callback1.WaitForResult(); |
| 7633 | EXPECT_THAT(rv, IsOk()); |
| 7634 | |
| 7635 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7636 | |
| 7637 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7638 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7639 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge)); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7640 | |
| 7641 | TestCompletionCallback callback2; |
| 7642 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7643 | rv = trans.RestartWithAuth( |
| 7644 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7645 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7647 | |
| 7648 | rv = callback2.WaitForResult(); |
| 7649 | EXPECT_THAT(rv, IsOk()); |
| 7650 | |
| 7651 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7652 | |
| 7653 | response = trans.GetResponseInfo(); |
| 7654 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7655 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7656 | |
| 7657 | TestCompletionCallback callback3; |
| 7658 | |
| 7659 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7661 | |
| 7662 | rv = callback3.WaitForResult(); |
| 7663 | EXPECT_THAT(rv, IsOk()); |
| 7664 | |
| 7665 | response = trans.GetResponseInfo(); |
| 7666 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7667 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7668 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7669 | |
| 7670 | std::string response_data; |
| 7671 | rv = ReadTransaction(&trans, &response_data); |
| 7672 | EXPECT_THAT(rv, IsOk()); |
| 7673 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7674 | |
| 7675 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7676 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7677 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7678 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7679 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7680 | |
| 7681 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7682 | // do no retry forever checking for TLS version interference. This is a |
| 7683 | // regression test for https://crbug.com/823387. |
| 7684 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7685 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7686 | // https://origin/. |
| 7687 | session_deps_.proxy_resolution_service = |
| 7688 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7689 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7690 | |
| 7691 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7692 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7693 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7694 | |
| 7695 | HttpRequestInfo request; |
| 7696 | request.method = "GET"; |
| 7697 | request.url = GURL("https://origin/"); |
| 7698 | request.traffic_annotation = |
| 7699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7700 | |
| 7701 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7702 | // to other auth schemes. |
| 7703 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7704 | |
| 7705 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7706 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7707 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7708 | |
| 7709 | // Generate the NTLM messages based on known test data. |
| 7710 | std::string negotiate_msg; |
| 7711 | std::string challenge_msg; |
| 7712 | std::string authenticate_msg; |
| 7713 | base::Base64Encode( |
| 7714 | base::StringPiece( |
| 7715 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7716 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7717 | &negotiate_msg); |
| 7718 | base::Base64Encode( |
| 7719 | base::StringPiece( |
| 7720 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7721 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7722 | &challenge_msg); |
| 7723 | base::Base64Encode( |
| 7724 | base::StringPiece( |
| 7725 | reinterpret_cast<const char*>( |
| 7726 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7727 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7728 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7729 | &authenticate_msg); |
| 7730 | |
| 7731 | MockWrite data_writes[] = { |
| 7732 | // The initial CONNECT request. |
| 7733 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7734 | "Host: origin:443\r\n" |
| 7735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7736 | |
| 7737 | // After restarting with an identity. |
| 7738 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7739 | "Host: origin:443\r\n" |
| 7740 | "Proxy-Connection: keep-alive\r\n" |
| 7741 | "Proxy-Authorization: NTLM "), |
| 7742 | MockWrite(negotiate_msg.c_str()), |
| 7743 | // End headers. |
| 7744 | MockWrite("\r\n\r\n"), |
| 7745 | |
| 7746 | // The second restart. |
| 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(authenticate_msg.c_str()), |
| 7752 | // End headers. |
| 7753 | MockWrite("\r\n\r\n"), |
| 7754 | }; |
| 7755 | |
| 7756 | MockRead data_reads[] = { |
| 7757 | // The initial NTLM response. |
| 7758 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7759 | "Content-Length: 0\r\n" |
| 7760 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7761 | |
| 7762 | // The NTLM challenge message. |
| 7763 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7764 | "Content-Length: 0\r\n" |
| 7765 | "Proxy-Authenticate: NTLM "), |
| 7766 | MockRead(challenge_msg.c_str()), |
| 7767 | // End headers. |
| 7768 | MockRead("\r\n\r\n"), |
| 7769 | |
| 7770 | // Finally the tunnel is established. |
| 7771 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7772 | }; |
| 7773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7774 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7775 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7776 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7777 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7778 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7780 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7781 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7783 | |
| 7784 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7785 | // request. |
| 7786 | TestCompletionCallback callback; |
| 7787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7788 | int rv = callback.GetResult( |
| 7789 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7790 | |
| 7791 | EXPECT_THAT(rv, IsOk()); |
| 7792 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7793 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7794 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7795 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge)); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7796 | |
| 7797 | // Configure credentials. The proxy responds with the challenge message. |
| 7798 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7799 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7800 | callback.callback())); |
| 7801 | EXPECT_THAT(rv, IsOk()); |
| 7802 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7803 | response = trans.GetResponseInfo(); |
| 7804 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7805 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7806 | |
| 7807 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7808 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7809 | // restart the process. The proxy responds with another NTLM authentiation |
| 7810 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7811 | rv = callback.GetResult( |
| 7812 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7813 | EXPECT_THAT(rv, IsOk()); |
| 7814 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7815 | response = trans.GetResponseInfo(); |
| 7816 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7817 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7818 | |
| 7819 | // The proxy responds with the NTLM challenge message. |
| 7820 | rv = callback.GetResult( |
| 7821 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7822 | EXPECT_THAT(rv, IsOk()); |
| 7823 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7824 | response = trans.GetResponseInfo(); |
| 7825 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 7826 | EXPECT_FALSE(response->auth_challenge.has_value()); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7827 | |
| 7828 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7829 | // handshake resets again. We should not retry again. |
| 7830 | rv = callback.GetResult( |
| 7831 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7832 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7833 | } |
| 7834 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7835 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7836 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | // Test reading a server response which has only headers, and no body. |
| 7838 | // After some maximum number of bytes is consumed, the transaction should |
| 7839 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7840 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7841 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7843 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7844 | request.traffic_annotation = |
| 7845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7849 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7850 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7851 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7852 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7853 | |
| 7854 | MockRead data_reads[] = { |
| 7855 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7856 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7857 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7859 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7860 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7863 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7867 | |
| 7868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7869 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7870 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7871 | |
| 7872 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7873 | // establish tunnel. |
| 7874 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7875 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7876 | HttpRequestInfo request; |
| 7877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7878 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7879 | request.traffic_annotation = |
| 7880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7881 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7882 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7883 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7884 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7887 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7888 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7889 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7890 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7891 | // Since we have proxy, should try to establish tunnel. |
| 7892 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7893 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7894 | "Host: www.example.org:443\r\n" |
| 7895 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | }; |
| 7897 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7898 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7899 | // connection. Usually a proxy would return 501 (not implemented), |
| 7900 | // or 200 (tunnel established). |
| 7901 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7902 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7903 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7904 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7905 | }; |
| 7906 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7907 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7910 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7912 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7914 | |
| 7915 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7916 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7917 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7918 | // Empty the current queue. This is necessary because idle sockets are |
| 7919 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7920 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7921 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7922 | // We now check to make sure the TCPClientSocket was not added back to |
| 7923 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7924 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7925 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7926 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7927 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7928 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7929 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7930 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7931 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7932 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7933 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7935 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7936 | request.traffic_annotation = |
| 7937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7942 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7943 | MockRead data_reads[] = { |
| 7944 | // A part of the response body is received with the response headers. |
| 7945 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7946 | // The rest of the response body is received in two parts. |
| 7947 | MockRead("lo"), |
| 7948 | MockRead(" world"), |
| 7949 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7950 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7951 | }; |
| 7952 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7953 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7954 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7955 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7956 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7960 | |
| 7961 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7964 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7965 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7966 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7967 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7968 | std::string status_line = response->headers->GetStatusLine(); |
| 7969 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7970 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7971 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7972 | |
| 7973 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7974 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7975 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7976 | EXPECT_EQ("hello world", response_data); |
| 7977 | |
| 7978 | // Empty the current queue. This is necessary because idle sockets are |
| 7979 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7980 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7981 | |
| 7982 | // 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] | 7983 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7984 | } |
| 7985 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7986 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7987 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7988 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7989 | HttpRequestInfo request; |
| 7990 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7991 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7992 | request.traffic_annotation = |
| 7993 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | |
| 7995 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7996 | MockWrite( |
| 7997 | "GET / HTTP/1.1\r\n" |
| 7998 | "Host: www.example.org\r\n" |
| 7999 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8000 | }; |
| 8001 | |
| 8002 | MockRead data_reads[] = { |
| 8003 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8004 | MockRead("Content-Length: 11\r\n\r\n"), |
| 8005 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8006 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8007 | }; |
| 8008 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8009 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8012 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8015 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8019 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8020 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8021 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8023 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8025 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8026 | ASSERT_TRUE(response); |
| 8027 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8028 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8029 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8030 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8031 | |
| 8032 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8033 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8034 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8035 | EXPECT_EQ("hello world", response_data); |
| 8036 | |
| 8037 | // Empty the current queue. This is necessary because idle sockets are |
| 8038 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8039 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8040 | |
| 8041 | // 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] | 8042 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8043 | } |
| 8044 | |
| 8045 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8046 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8047 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8048 | HttpRequestInfo request; |
| 8049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8050 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8051 | request.traffic_annotation = |
| 8052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8053 | |
| 8054 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8055 | MockWrite( |
| 8056 | "GET / HTTP/1.1\r\n" |
| 8057 | "Host: www.example.org\r\n" |
| 8058 | "Connection: keep-alive\r\n\r\n"), |
| 8059 | MockWrite( |
| 8060 | "GET / HTTP/1.1\r\n" |
| 8061 | "Host: www.example.org\r\n" |
| 8062 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8063 | }; |
| 8064 | |
| 8065 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8066 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8067 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8068 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8069 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8070 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8073 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8074 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8075 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8077 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8079 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8082 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8083 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8084 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8085 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8086 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8088 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8089 | |
| 8090 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8091 | ASSERT_TRUE(response); |
| 8092 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8093 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8094 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8095 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8096 | |
| 8097 | std::string response_data; |
| 8098 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8100 | EXPECT_EQ("hello world", response_data); |
| 8101 | |
| 8102 | // Empty the current queue. This is necessary because idle sockets are |
| 8103 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8104 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | |
| 8106 | // 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] | 8107 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8108 | |
| 8109 | // Now start the second transaction, which should reuse the previous socket. |
| 8110 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8111 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8112 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8113 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8114 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8115 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8117 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8118 | |
| 8119 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8120 | ASSERT_TRUE(response); |
| 8121 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8122 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8123 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8124 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8125 | |
| 8126 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8128 | EXPECT_EQ("hello world", response_data); |
| 8129 | |
| 8130 | // Empty the current queue. This is necessary because idle sockets are |
| 8131 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8132 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8133 | |
| 8134 | // 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] | 8135 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8136 | } |
| 8137 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8138 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8139 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8140 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8141 | HttpRequestInfo request; |
| 8142 | request.method = "GET"; |
| 8143 | request.url = GURL("http://www.example.org/"); |
| 8144 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8145 | request.traffic_annotation = |
| 8146 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8147 | |
| 8148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8150 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8151 | |
| 8152 | MockRead data_reads[] = { |
| 8153 | // A part of the response body is received with the response headers. |
| 8154 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8155 | // The rest of the response body is received in two parts. |
| 8156 | MockRead("lo"), MockRead(" world"), |
| 8157 | MockRead("junk"), // Should not be read!! |
| 8158 | MockRead(SYNCHRONOUS, OK), |
| 8159 | }; |
| 8160 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8161 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8162 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8163 | |
| 8164 | TestCompletionCallback callback; |
| 8165 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8166 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8168 | |
| 8169 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8171 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8172 | ASSERT_TRUE(response); |
| 8173 | EXPECT_TRUE(response->headers); |
| 8174 | std::string status_line = response->headers->GetStatusLine(); |
| 8175 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8176 | |
| 8177 | // Make memory critical notification and ensure the transaction still has been |
| 8178 | // operating right. |
| 8179 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8180 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8181 | base::RunLoop().RunUntilIdle(); |
| 8182 | |
| 8183 | // Socket should not be flushed as long as it is not idle. |
| 8184 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8185 | |
| 8186 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8187 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8188 | EXPECT_THAT(rv, IsOk()); |
| 8189 | EXPECT_EQ("hello world", response_data); |
| 8190 | |
| 8191 | // Empty the current queue. This is necessary because idle sockets are |
| 8192 | // added to the connection pool asynchronously with a PostTask. |
| 8193 | base::RunLoop().RunUntilIdle(); |
| 8194 | |
| 8195 | // We now check to make sure the socket was added back to the pool. |
| 8196 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8197 | |
| 8198 | // Idle sockets should be flushed now. |
| 8199 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8200 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8201 | base::RunLoop().RunUntilIdle(); |
| 8202 | |
| 8203 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8204 | } |
| 8205 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8206 | // Disable idle socket closing on memory pressure. |
| 8207 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8208 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8209 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8210 | HttpRequestInfo request; |
| 8211 | request.method = "GET"; |
| 8212 | request.url = GURL("http://www.example.org/"); |
| 8213 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8214 | request.traffic_annotation = |
| 8215 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8216 | |
| 8217 | // Disable idle socket closing on memory pressure. |
| 8218 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8219 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8220 | |
| 8221 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8222 | |
| 8223 | MockRead data_reads[] = { |
| 8224 | // A part of the response body is received with the response headers. |
| 8225 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8226 | // The rest of the response body is received in two parts. |
| 8227 | MockRead("lo"), MockRead(" world"), |
| 8228 | MockRead("junk"), // Should not be read!! |
| 8229 | MockRead(SYNCHRONOUS, OK), |
| 8230 | }; |
| 8231 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8232 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8233 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8234 | |
| 8235 | TestCompletionCallback callback; |
| 8236 | |
| 8237 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8239 | |
| 8240 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8241 | |
| 8242 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8243 | ASSERT_TRUE(response); |
| 8244 | EXPECT_TRUE(response->headers); |
| 8245 | std::string status_line = response->headers->GetStatusLine(); |
| 8246 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8247 | |
| 8248 | // Make memory critical notification and ensure the transaction still has been |
| 8249 | // operating right. |
| 8250 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8251 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8252 | base::RunLoop().RunUntilIdle(); |
| 8253 | |
| 8254 | // Socket should not be flushed as long as it is not idle. |
| 8255 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8256 | |
| 8257 | std::string response_data; |
| 8258 | rv = ReadTransaction(&trans, &response_data); |
| 8259 | EXPECT_THAT(rv, IsOk()); |
| 8260 | EXPECT_EQ("hello world", response_data); |
| 8261 | |
| 8262 | // Empty the current queue. This is necessary because idle sockets are |
| 8263 | // added to the connection pool asynchronously with a PostTask. |
| 8264 | base::RunLoop().RunUntilIdle(); |
| 8265 | |
| 8266 | // We now check to make sure the socket was added back to the pool. |
| 8267 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8268 | |
| 8269 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8270 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8271 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8272 | base::RunLoop().RunUntilIdle(); |
| 8273 | |
| 8274 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8275 | |
| 8276 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8277 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8278 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8279 | base::RunLoop().RunUntilIdle(); |
| 8280 | |
| 8281 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8282 | } |
| 8283 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8284 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8285 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8286 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8287 | HttpRequestInfo request; |
| 8288 | request.method = "GET"; |
| 8289 | request.url = GURL("https://www.example.org/"); |
| 8290 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8291 | request.traffic_annotation = |
| 8292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8293 | |
| 8294 | MockWrite data_writes[] = { |
| 8295 | MockWrite("GET / HTTP/1.1\r\n" |
| 8296 | "Host: www.example.org\r\n" |
| 8297 | "Connection: keep-alive\r\n\r\n"), |
| 8298 | }; |
| 8299 | |
| 8300 | MockRead data_reads[] = { |
| 8301 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8302 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8303 | |
| 8304 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8306 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8307 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8308 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8309 | |
| 8310 | TestCompletionCallback callback; |
| 8311 | |
| 8312 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8313 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8314 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8315 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8316 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8317 | |
| 8318 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8320 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8321 | ASSERT_TRUE(response); |
| 8322 | ASSERT_TRUE(response->headers); |
| 8323 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8324 | |
| 8325 | // Make memory critical notification and ensure the transaction still has been |
| 8326 | // operating right. |
| 8327 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8328 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8329 | base::RunLoop().RunUntilIdle(); |
| 8330 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8331 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8332 | |
| 8333 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8334 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8335 | EXPECT_THAT(rv, IsOk()); |
| 8336 | EXPECT_EQ("hello world", response_data); |
| 8337 | |
| 8338 | // Empty the current queue. This is necessary because idle sockets are |
| 8339 | // added to the connection pool asynchronously with a PostTask. |
| 8340 | base::RunLoop().RunUntilIdle(); |
| 8341 | |
| 8342 | // 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] | 8343 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8344 | |
| 8345 | // Make memory notification once again and ensure idle socket is closed. |
| 8346 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8347 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8348 | base::RunLoop().RunUntilIdle(); |
| 8349 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8350 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8351 | } |
| 8352 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8353 | // Make sure that we recycle a socket after a zero-length response. |
| 8354 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8355 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8356 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8357 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8358 | request.url = GURL( |
| 8359 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8360 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8361 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8362 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8363 | request.traffic_annotation = |
| 8364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8366 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8367 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8368 | MockRead data_reads[] = { |
| 8369 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8370 | "Content-Length: 0\r\n" |
| 8371 | "Content-Type: text/html\r\n\r\n"), |
| 8372 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8373 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8374 | }; |
| 8375 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8376 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8378 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8379 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8380 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8381 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8383 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8384 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8385 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8387 | |
| 8388 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8392 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8393 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8394 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8395 | std::string status_line = response->headers->GetStatusLine(); |
| 8396 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8397 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8398 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8399 | |
| 8400 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8401 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8402 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8403 | EXPECT_EQ("", response_data); |
| 8404 | |
| 8405 | // Empty the current queue. This is necessary because idle sockets are |
| 8406 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8407 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8408 | |
| 8409 | // 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] | 8410 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8411 | } |
| 8412 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8413 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8414 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8415 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8416 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8417 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8418 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8419 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8420 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8421 | // after use. |
| 8422 | request[0].method = "GET"; |
| 8423 | request[0].url = GURL("http://www.google.com/"); |
| 8424 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8425 | request[0].traffic_annotation = |
| 8426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8427 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8428 | // transaction 1. The first attempts fails when writing the POST data. |
| 8429 | // This causes the transaction to retry with a new socket. The second |
| 8430 | // attempt succeeds. |
| 8431 | request[1].method = "POST"; |
| 8432 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8433 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8434 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8435 | request[1].traffic_annotation = |
| 8436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8439 | |
| 8440 | // The first socket is used for transaction 1 and the first attempt of |
| 8441 | // transaction 2. |
| 8442 | |
| 8443 | // The response of transaction 1. |
| 8444 | MockRead data_reads1[] = { |
| 8445 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8446 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8447 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8448 | }; |
| 8449 | // The mock write results of transaction 1 and the first attempt of |
| 8450 | // transaction 2. |
| 8451 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8452 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8453 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8454 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8455 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8456 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | |
| 8458 | // The second socket is used for the second attempt of transaction 2. |
| 8459 | |
| 8460 | // The response of transaction 2. |
| 8461 | MockRead data_reads2[] = { |
| 8462 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8463 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8465 | }; |
| 8466 | // The mock write results of the second attempt of transaction 2. |
| 8467 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8468 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8469 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8470 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8471 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8473 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8474 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8475 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8476 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8477 | "hello world", "welcome" |
| 8478 | }; |
| 8479 | |
| 8480 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8481 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8483 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8485 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8487 | |
| 8488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8489 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8491 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8492 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8493 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8494 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8495 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8496 | |
| 8497 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8498 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8499 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8500 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8501 | } |
| 8502 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8503 | |
| 8504 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8505 | // 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] | 8506 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8507 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8508 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8509 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8510 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8511 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8512 | request.traffic_annotation = |
| 8513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8517 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8518 | // The password contains an escaped character -- for this test to pass it |
| 8519 | // will need to be unescaped by HttpNetworkTransaction. |
| 8520 | EXPECT_EQ("b%40r", request.url.password()); |
| 8521 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8522 | MockWrite data_writes1[] = { |
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\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8527 | }; |
| 8528 | |
| 8529 | MockRead data_reads1[] = { |
| 8530 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8531 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8532 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8533 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8534 | }; |
| 8535 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8536 | // After the challenge above, the transaction will be restarted using the |
| 8537 | // identity from the url (foo, b@r) to answer the challenge. |
| 8538 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8539 | MockWrite( |
| 8540 | "GET / HTTP/1.1\r\n" |
| 8541 | "Host: www.example.org\r\n" |
| 8542 | "Connection: keep-alive\r\n" |
| 8543 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8544 | }; |
| 8545 | |
| 8546 | MockRead data_reads2[] = { |
| 8547 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8548 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8549 | MockRead(SYNCHRONOUS, OK), |
| 8550 | }; |
| 8551 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8552 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8553 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8554 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8555 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8557 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8558 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8560 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8561 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8562 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8563 | |
| 8564 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8565 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8567 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8568 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8569 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8572 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8573 | |
| 8574 | // There is no challenge info, since the identity in URL worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8575 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8576 | |
| 8577 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8578 | |
| 8579 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8580 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8581 | } |
| 8582 | |
| 8583 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8584 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8585 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8586 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8587 | HttpRequestInfo request; |
| 8588 | request.method = "GET"; |
| 8589 | // Note: the URL has a username:password in it. The password "baz" is |
| 8590 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8591 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8592 | |
| 8593 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8594 | request.traffic_annotation = |
| 8595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8596 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8599 | |
| 8600 | MockWrite data_writes1[] = { |
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\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8605 | }; |
| 8606 | |
| 8607 | MockRead data_reads1[] = { |
| 8608 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8609 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8610 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8611 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8612 | }; |
| 8613 | |
| 8614 | // After the challenge above, the transaction will be restarted using the |
| 8615 | // identity from the url (foo, baz) to answer the challenge. |
| 8616 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8617 | MockWrite( |
| 8618 | "GET / HTTP/1.1\r\n" |
| 8619 | "Host: www.example.org\r\n" |
| 8620 | "Connection: keep-alive\r\n" |
| 8621 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8622 | }; |
| 8623 | |
| 8624 | MockRead data_reads2[] = { |
| 8625 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8627 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8628 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8629 | }; |
| 8630 | |
| 8631 | // After the challenge above, the transaction will be restarted using the |
| 8632 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8633 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8634 | MockWrite( |
| 8635 | "GET / HTTP/1.1\r\n" |
| 8636 | "Host: www.example.org\r\n" |
| 8637 | "Connection: keep-alive\r\n" |
| 8638 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8639 | }; |
| 8640 | |
| 8641 | MockRead data_reads3[] = { |
| 8642 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8643 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8644 | MockRead(SYNCHRONOUS, OK), |
| 8645 | }; |
| 8646 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8647 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8648 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8649 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8650 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8651 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8652 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | |
| 8654 | TestCompletionCallback callback1; |
| 8655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8656 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8658 | |
| 8659 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8660 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8664 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8666 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8667 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8668 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8670 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8671 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8672 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8673 | |
| 8674 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8675 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8677 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8678 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8679 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8681 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8682 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8683 | |
| 8684 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8685 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8686 | |
| 8687 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8688 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8689 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8690 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8691 | } |
| 8692 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8693 | |
| 8694 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8695 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8696 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8697 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8698 | HttpRequestInfo request; |
| 8699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8700 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8701 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8702 | request.traffic_annotation = |
| 8703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8707 | |
| 8708 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8709 | MockWrite( |
| 8710 | "GET / HTTP/1.1\r\n" |
| 8711 | "Host: www.example.org\r\n" |
| 8712 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8713 | }; |
| 8714 | |
| 8715 | MockRead data_reads1[] = { |
| 8716 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8717 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8718 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8719 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8720 | }; |
| 8721 | |
| 8722 | // After the challenge above, the transaction will be restarted using the |
| 8723 | // identity supplied by the user, not the one in the URL, to answer the |
| 8724 | // challenge. |
| 8725 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8726 | MockWrite( |
| 8727 | "GET / HTTP/1.1\r\n" |
| 8728 | "Host: www.example.org\r\n" |
| 8729 | "Connection: keep-alive\r\n" |
| 8730 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8731 | }; |
| 8732 | |
| 8733 | MockRead data_reads3[] = { |
| 8734 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8735 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8736 | MockRead(SYNCHRONOUS, OK), |
| 8737 | }; |
| 8738 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8739 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8740 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8741 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8742 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8743 | |
| 8744 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8745 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8747 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8748 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8749 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8751 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8752 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8753 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8754 | |
| 8755 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8756 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8759 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8760 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8762 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8763 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8764 | |
| 8765 | // There is no challenge info, since the identity worked. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8766 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8767 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8768 | |
| 8769 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8770 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8771 | } |
| 8772 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8773 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8774 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8776 | |
| 8777 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8778 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8779 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8781 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8782 | request.traffic_annotation = |
| 8783 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8784 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8786 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8787 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8788 | MockWrite( |
| 8789 | "GET /x/y/z HTTP/1.1\r\n" |
| 8790 | "Host: www.example.org\r\n" |
| 8791 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8792 | }; |
| 8793 | |
| 8794 | MockRead data_reads1[] = { |
| 8795 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8796 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8797 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8798 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8799 | }; |
| 8800 | |
| 8801 | // Resend with authorization (username=foo, password=bar) |
| 8802 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8803 | MockWrite( |
| 8804 | "GET /x/y/z HTTP/1.1\r\n" |
| 8805 | "Host: www.example.org\r\n" |
| 8806 | "Connection: keep-alive\r\n" |
| 8807 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8808 | }; |
| 8809 | |
| 8810 | // Sever accepts the authorization. |
| 8811 | MockRead data_reads2[] = { |
| 8812 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8813 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8814 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8815 | }; |
| 8816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8817 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8818 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8819 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8820 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8822 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8823 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8824 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
| 8827 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8830 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8831 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8832 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8834 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8836 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8837 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8839 | |
| 8840 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8841 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8843 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8844 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8845 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8846 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8847 | } |
| 8848 | |
| 8849 | // ------------------------------------------------------------------------ |
| 8850 | |
| 8851 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8852 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8853 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8854 | request.method = "GET"; |
| 8855 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8856 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8857 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8858 | request.traffic_annotation = |
| 8859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8862 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8863 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8864 | MockWrite( |
| 8865 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8866 | "Host: www.example.org\r\n" |
| 8867 | "Connection: keep-alive\r\n" |
| 8868 | // Send preemptive authorization for MyRealm1 |
| 8869 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8870 | }; |
| 8871 | |
| 8872 | // The server didn't like the preemptive authorization, and |
| 8873 | // challenges us for a different realm (MyRealm2). |
| 8874 | MockRead data_reads1[] = { |
| 8875 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8876 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8877 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8878 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8879 | }; |
| 8880 | |
| 8881 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8882 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8883 | MockWrite( |
| 8884 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8885 | "Host: www.example.org\r\n" |
| 8886 | "Connection: keep-alive\r\n" |
| 8887 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8888 | }; |
| 8889 | |
| 8890 | // Sever accepts the authorization. |
| 8891 | MockRead data_reads2[] = { |
| 8892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8893 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8894 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8895 | }; |
| 8896 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8897 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8898 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8902 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8904 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8906 | |
| 8907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8908 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8911 | ASSERT_TRUE(response); |
| 8912 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8913 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8914 | EXPECT_EQ("http://www.example.org", |
| 8915 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8916 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8917 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8919 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8920 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8921 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8922 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8924 | |
| 8925 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8928 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8929 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8930 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8932 | } |
| 8933 | |
| 8934 | // ------------------------------------------------------------------------ |
| 8935 | |
| 8936 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8937 | // succeed with preemptive authorization. |
| 8938 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8939 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8941 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8942 | request.traffic_annotation = |
| 8943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8946 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8947 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8948 | MockWrite( |
| 8949 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8950 | "Host: www.example.org\r\n" |
| 8951 | "Connection: keep-alive\r\n" |
| 8952 | // The authorization for MyRealm1 gets sent preemptively |
| 8953 | // (since the url is in the same protection space) |
| 8954 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | }; |
| 8956 | |
| 8957 | // Sever accepts the preemptive authorization |
| 8958 | MockRead data_reads1[] = { |
| 8959 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8960 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8961 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8962 | }; |
| 8963 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8964 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8967 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8968 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8969 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8971 | |
| 8972 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8975 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8976 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8977 | |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 8978 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8980 | } |
| 8981 | |
| 8982 | // ------------------------------------------------------------------------ |
| 8983 | |
| 8984 | // Transaction 4: request another URL in MyRealm (however the |
| 8985 | // url is not known to belong to the protection space, so no pre-auth). |
| 8986 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8987 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8988 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8989 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8990 | request.traffic_annotation = |
| 8991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8994 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8995 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8996 | MockWrite( |
| 8997 | "GET /x/1 HTTP/1.1\r\n" |
| 8998 | "Host: www.example.org\r\n" |
| 8999 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9000 | }; |
| 9001 | |
| 9002 | MockRead data_reads1[] = { |
| 9003 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9004 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9005 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9006 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9007 | }; |
| 9008 | |
| 9009 | // Resend with authorization from MyRealm's cache. |
| 9010 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9011 | MockWrite( |
| 9012 | "GET /x/1 HTTP/1.1\r\n" |
| 9013 | "Host: www.example.org\r\n" |
| 9014 | "Connection: keep-alive\r\n" |
| 9015 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9016 | }; |
| 9017 | |
| 9018 | // Sever accepts the authorization. |
| 9019 | MockRead data_reads2[] = { |
| 9020 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9021 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9023 | }; |
| 9024 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9025 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9026 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9027 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9028 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9030 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9032 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9034 | |
| 9035 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9038 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9039 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9040 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9041 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9042 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9043 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9044 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9046 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9047 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9048 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9049 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9050 | } |
| 9051 | |
| 9052 | // ------------------------------------------------------------------------ |
| 9053 | |
| 9054 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9055 | // cached identity. Should invalidate and re-prompt. |
| 9056 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9057 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9058 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9059 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9060 | request.traffic_annotation = |
| 9061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9063 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9064 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9065 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9066 | MockWrite( |
| 9067 | "GET /p/q/t HTTP/1.1\r\n" |
| 9068 | "Host: www.example.org\r\n" |
| 9069 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9070 | }; |
| 9071 | |
| 9072 | MockRead data_reads1[] = { |
| 9073 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9074 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9075 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9076 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9077 | }; |
| 9078 | |
| 9079 | // Resend with authorization from cache for MyRealm. |
| 9080 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9081 | MockWrite( |
| 9082 | "GET /p/q/t HTTP/1.1\r\n" |
| 9083 | "Host: www.example.org\r\n" |
| 9084 | "Connection: keep-alive\r\n" |
| 9085 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9086 | }; |
| 9087 | |
| 9088 | // Sever rejects the authorization. |
| 9089 | MockRead data_reads2[] = { |
| 9090 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9091 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9092 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9093 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9094 | }; |
| 9095 | |
| 9096 | // At this point we should prompt for new credentials for MyRealm. |
| 9097 | // Restart with username=foo3, password=foo4. |
| 9098 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9099 | MockWrite( |
| 9100 | "GET /p/q/t HTTP/1.1\r\n" |
| 9101 | "Host: www.example.org\r\n" |
| 9102 | "Connection: keep-alive\r\n" |
| 9103 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9104 | }; |
| 9105 | |
| 9106 | // Sever accepts the authorization. |
| 9107 | MockRead data_reads3[] = { |
| 9108 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9109 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9110 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9111 | }; |
| 9112 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9113 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9114 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9115 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9116 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9117 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9118 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9120 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9121 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9122 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9124 | |
| 9125 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9126 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9127 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9128 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9129 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9130 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9132 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9134 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9136 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9137 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9138 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9140 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9142 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9143 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9145 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9146 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9147 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9149 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9150 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9151 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9152 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9153 | } |
| 9154 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9155 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9156 | // Tests that nonce count increments when multiple auth attempts |
| 9157 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9158 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9159 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9160 | new HttpAuthHandlerDigest::Factory(); |
| 9161 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9162 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9163 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9164 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9165 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9166 | |
| 9167 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9168 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9169 | HttpRequestInfo request; |
| 9170 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9171 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9172 | request.traffic_annotation = |
| 9173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9175 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9176 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9177 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9178 | MockWrite( |
| 9179 | "GET /x/y/z HTTP/1.1\r\n" |
| 9180 | "Host: www.example.org\r\n" |
| 9181 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9182 | }; |
| 9183 | |
| 9184 | MockRead data_reads1[] = { |
| 9185 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9186 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9187 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9188 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9189 | }; |
| 9190 | |
| 9191 | // Resend with authorization (username=foo, password=bar) |
| 9192 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9193 | MockWrite( |
| 9194 | "GET /x/y/z HTTP/1.1\r\n" |
| 9195 | "Host: www.example.org\r\n" |
| 9196 | "Connection: keep-alive\r\n" |
| 9197 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9198 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9199 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9200 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | }; |
| 9202 | |
| 9203 | // Sever accepts the authorization. |
| 9204 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9205 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9206 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9207 | }; |
| 9208 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9209 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9210 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9211 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9212 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9214 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9215 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9216 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
| 9219 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9223 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9224 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9226 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9228 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9229 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9231 | |
| 9232 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9235 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9236 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9237 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9238 | } |
| 9239 | |
| 9240 | // ------------------------------------------------------------------------ |
| 9241 | |
| 9242 | // Transaction 2: Request another resource in digestive's protection space. |
| 9243 | // This will preemptively add an Authorization header which should have an |
| 9244 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9245 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9246 | HttpRequestInfo request; |
| 9247 | request.method = "GET"; |
| 9248 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9249 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9250 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9251 | request.traffic_annotation = |
| 9252 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9255 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9256 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9257 | MockWrite( |
| 9258 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9259 | "Host: www.example.org\r\n" |
| 9260 | "Connection: keep-alive\r\n" |
| 9261 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9262 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9263 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9264 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9265 | }; |
| 9266 | |
| 9267 | // Sever accepts the authorization. |
| 9268 | MockRead data_reads1[] = { |
| 9269 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9270 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9271 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9272 | }; |
| 9273 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9274 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9275 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9277 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9278 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9279 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9281 | |
| 9282 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9285 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9286 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9287 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9288 | } |
| 9289 | } |
| 9290 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9291 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9292 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9293 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9296 | |
| 9297 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9298 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9299 | trans.read_buf_len_ = 15; |
| 9300 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9301 | |
| 9302 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9303 | HttpResponseInfo* response = &trans.response_; |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9304 | response->auth_challenge = base::nullopt; |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9305 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9306 | response->response_time = base::Time::Now(); |
| 9307 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9308 | |
| 9309 | { // Setup state for response_.vary_data |
| 9310 | HttpRequestInfo request; |
| 9311 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9312 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9313 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9314 | request.extra_headers.SetHeader("Foo", "1"); |
| 9315 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9316 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9317 | } |
| 9318 | |
| 9319 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9320 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9321 | |
| 9322 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9323 | EXPECT_FALSE(trans.read_buf_); |
| 9324 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9325 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9326 | EXPECT_FALSE(response->auth_challenge.has_value()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9327 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9328 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9329 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9330 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9331 | } |
| 9332 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9333 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9334 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9335 | HttpRequestInfo request; |
| 9336 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9337 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9338 | request.traffic_annotation = |
| 9339 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9342 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9343 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9344 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9345 | MockWrite( |
| 9346 | "GET / HTTP/1.1\r\n" |
| 9347 | "Host: www.example.org\r\n" |
| 9348 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9349 | }; |
| 9350 | |
| 9351 | MockRead data_reads[] = { |
| 9352 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9354 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9355 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9356 | }; |
| 9357 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9358 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9359 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9360 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9361 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9362 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9363 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9368 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9369 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9370 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9372 | |
| 9373 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9374 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9376 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9378 | |
| 9379 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9382 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9383 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9384 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9385 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9386 | } |
| 9387 | |
| 9388 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9389 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9390 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9391 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9392 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9393 | |
| 9394 | HttpRequestInfo request; |
| 9395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9396 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9397 | request.traffic_annotation = |
| 9398 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9399 | |
| 9400 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9401 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9402 | "Host: www.example.org:443\r\n" |
| 9403 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9404 | }; |
| 9405 | |
| 9406 | MockRead proxy_reads[] = { |
| 9407 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9408 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9409 | }; |
| 9410 | |
| 9411 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9412 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9413 | "Host: www.example.org:443\r\n" |
| 9414 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9415 | MockWrite("GET / HTTP/1.1\r\n" |
| 9416 | "Host: www.example.org\r\n" |
| 9417 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9418 | }; |
| 9419 | |
| 9420 | MockRead data_reads[] = { |
| 9421 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9422 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9423 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9424 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9426 | }; |
| 9427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9428 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9429 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9430 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9431 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9432 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9433 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9438 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9439 | |
| 9440 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9441 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9445 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9446 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | |
| 9449 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9450 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9451 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9452 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9454 | |
| 9455 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9456 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9459 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9460 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9461 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9462 | } |
| 9463 | } |
| 9464 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9465 | |
| 9466 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9467 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9468 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9469 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9470 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9471 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9472 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9473 | |
| 9474 | HttpRequestInfo request; |
| 9475 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9476 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9477 | request.traffic_annotation = |
| 9478 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9479 | |
| 9480 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9481 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9482 | "Host: www.example.org:443\r\n" |
| 9483 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9484 | MockWrite("GET / HTTP/1.1\r\n" |
| 9485 | "Host: www.example.org\r\n" |
| 9486 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9487 | }; |
| 9488 | |
| 9489 | MockRead data_reads[] = { |
| 9490 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9491 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9492 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9493 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9494 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9495 | }; |
| 9496 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9497 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9498 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9499 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9500 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9505 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9509 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9510 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9511 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9512 | |
| 9513 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9514 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9515 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9516 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9517 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9518 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9519 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9520 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9521 | EXPECT_EQ(200, response->headers->response_code()); |
| 9522 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9523 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9524 | |
| 9525 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9526 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9527 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9528 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9529 | } |
| 9530 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9531 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9532 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9533 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9534 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9535 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9536 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9537 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9538 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9539 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9540 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9541 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9542 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9543 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9545 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9546 | request.traffic_annotation = |
| 9547 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9548 | |
| 9549 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9550 | MockWrite(ASYNC, 0, |
| 9551 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9552 | "Host: www.example.org:443\r\n" |
| 9553 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9554 | }; |
| 9555 | |
| 9556 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9557 | // Pause on first read. |
| 9558 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9559 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9560 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9561 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9562 | }; |
| 9563 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9564 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9565 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9566 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9570 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9571 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9573 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9574 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9575 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9576 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9577 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9578 | |
| 9579 | // Host resolution takes |kTimeIncrement|. |
| 9580 | FastForwardBy(kTimeIncrement); |
| 9581 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9582 | // request to instantly complete, and the async connect will start as well. |
| 9583 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9584 | |
| 9585 | // Connecting takes |kTimeIncrement|. |
| 9586 | FastForwardBy(kTimeIncrement); |
| 9587 | data.RunUntilPaused(); |
| 9588 | |
| 9589 | // The server takes |kTimeIncrement| to respond. |
| 9590 | FastForwardBy(kTimeIncrement); |
| 9591 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9592 | |
| 9593 | rv = callback.WaitForResult(); |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9594 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9595 | } |
| 9596 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9597 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9598 | TEST_F(HttpNetworkTransactionTest, |
| 9599 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9600 | base::HistogramTester histograms; |
| 9601 | session_deps_.proxy_resolution_service = |
| 9602 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9603 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9604 | TestNetLog net_log; |
| 9605 | session_deps_.net_log = &net_log; |
| 9606 | |
| 9607 | HttpRequestInfo request; |
| 9608 | request.method = "GET"; |
| 9609 | request.url = GURL("https://www.example.org/"); |
| 9610 | request.traffic_annotation = |
| 9611 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9612 | |
| 9613 | MockWrite data_writes[] = { |
| 9614 | MockWrite(ASYNC, 0, |
| 9615 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9616 | "Host: www.example.org:443\r\n" |
| 9617 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9618 | }; |
| 9619 | |
| 9620 | MockRead data_reads[] = { |
| 9621 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9622 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9623 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9624 | }; |
| 9625 | |
| 9626 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9627 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9628 | |
| 9629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9631 | |
| 9632 | TestCompletionCallback callback; |
| 9633 | |
| 9634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9636 | |
| 9637 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9639 | |
| 9640 | rv = callback.WaitForResult(); |
| 9641 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9642 | |
| 9643 | histograms.ExpectUniqueSample( |
| 9644 | "Net.Proxy.RedirectDuringConnect", |
| 9645 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9646 | } |
| 9647 | |
| 9648 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9649 | // request for main frames. |
| 9650 | TEST_F(HttpNetworkTransactionTest, |
| 9651 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9652 | base::HistogramTester histograms; |
| 9653 | session_deps_.proxy_resolution_service = |
| 9654 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9655 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9656 | TestNetLog net_log; |
| 9657 | session_deps_.net_log = &net_log; |
| 9658 | |
| 9659 | HttpRequestInfo request; |
| 9660 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9661 | request.method = "GET"; |
| 9662 | request.url = GURL("https://www.example.org/"); |
| 9663 | request.traffic_annotation = |
| 9664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9665 | |
| 9666 | MockWrite data_writes[] = { |
| 9667 | MockWrite(ASYNC, 0, |
| 9668 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9669 | "Host: www.example.org:443\r\n" |
| 9670 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9671 | }; |
| 9672 | |
| 9673 | MockRead data_reads[] = { |
| 9674 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9675 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9676 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9677 | }; |
| 9678 | |
| 9679 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9680 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9681 | |
| 9682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9684 | |
| 9685 | TestCompletionCallback callback; |
| 9686 | |
| 9687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9689 | |
| 9690 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9692 | |
| 9693 | rv = callback.WaitForResult(); |
| 9694 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9695 | |
| 9696 | histograms.ExpectUniqueSample( |
| 9697 | "Net.Proxy.RedirectDuringConnect", |
| 9698 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9699 | } |
| 9700 | |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9701 | // 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] | 9702 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9703 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9704 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9705 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9706 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9707 | TestNetLog net_log; |
| 9708 | session_deps_.net_log = &net_log; |
| 9709 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9710 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9711 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9712 | |
| 9713 | HttpRequestInfo request; |
| 9714 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9715 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9716 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9717 | request.traffic_annotation = |
| 9718 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9719 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9720 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9721 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9722 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9723 | spdy::SpdySerializedFrame goaway( |
| 9724 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9725 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9726 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9727 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9728 | }; |
| 9729 | |
| 9730 | static const char* const kExtraHeaders[] = { |
| 9731 | "location", |
| 9732 | "http://login.example.com/", |
| 9733 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9734 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9735 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9736 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9737 | // Pause on first read. |
| 9738 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9739 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9740 | }; |
| 9741 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9742 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9743 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9744 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9749 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9753 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9754 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9756 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9757 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9758 | // Host resolution takes |kTimeIncrement|. |
| 9759 | FastForwardBy(kTimeIncrement); |
| 9760 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9761 | // request to instantly complete, and the async connect will start as well. |
| 9762 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9763 | |
| 9764 | // Connecting takes |kTimeIncrement|. |
| 9765 | FastForwardBy(kTimeIncrement); |
| 9766 | data.RunUntilPaused(); |
| 9767 | |
| 9768 | FastForwardBy(kTimeIncrement); |
| 9769 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9770 | rv = callback.WaitForResult(); |
Eric Roman | 695a787 | 2019-04-16 21:53:29 | [diff] [blame] | 9771 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9772 | |
| 9773 | histograms.ExpectUniqueSample( |
| 9774 | "Net.Proxy.RedirectDuringConnect", |
| 9775 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9776 | } |
| 9777 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9778 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9779 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9780 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9781 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9782 | |
| 9783 | HttpRequestInfo request; |
| 9784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9785 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9786 | request.traffic_annotation = |
| 9787 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9788 | |
| 9789 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9790 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9791 | "Host: www.example.org:443\r\n" |
| 9792 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9793 | }; |
| 9794 | |
| 9795 | MockRead data_reads[] = { |
| 9796 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9797 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9798 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9799 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9800 | }; |
| 9801 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9802 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9803 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9804 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9808 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9813 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9815 | |
| 9816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9817 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9818 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9819 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9820 | } |
| 9821 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9822 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9823 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9824 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9825 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9826 | |
| 9827 | HttpRequestInfo request; |
| 9828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9830 | request.traffic_annotation = |
| 9831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9832 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9833 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9834 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9835 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9836 | spdy::SpdySerializedFrame rst( |
| 9837 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9838 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9839 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9840 | }; |
| 9841 | |
| 9842 | static const char* const kExtraHeaders[] = { |
| 9843 | "location", |
| 9844 | "http://login.example.com/", |
| 9845 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9846 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9847 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9848 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9849 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9850 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9851 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9852 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9853 | }; |
| 9854 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9855 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9856 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9857 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9858 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9862 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9863 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9866 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9867 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9868 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9869 | |
| 9870 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9871 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9872 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9873 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9874 | } |
| 9875 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9876 | // Test the request-challenge-retry sequence for basic auth, through |
| 9877 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9878 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9879 | HttpRequestInfo request; |
| 9880 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9881 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9882 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9883 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9884 | request.traffic_annotation = |
| 9885 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9886 | |
| 9887 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9888 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9889 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9890 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9891 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9892 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9893 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9894 | |
| 9895 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9896 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9897 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 9898 | HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9899 | spdy::SpdySerializedFrame rst( |
| 9900 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9901 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9903 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9904 | // be issuing -- the final header line contains the credentials. |
| 9905 | const char* const kAuthCredentials[] = { |
| 9906 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9907 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9908 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 9909 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, |
| 9910 | HttpProxyConnectJob::kH2QuicTunnelPriority, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9911 | HostPortPair("www.example.org", 443))); |
| 9912 | // fetch https://www.example.org/ via HTTP |
| 9913 | const char get[] = |
| 9914 | "GET / HTTP/1.1\r\n" |
| 9915 | "Host: www.example.org\r\n" |
| 9916 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9917 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9918 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9919 | |
| 9920 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9921 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9922 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9923 | }; |
| 9924 | |
| 9925 | // The proxy responds to the connect with a 407, using a persistent |
| 9926 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9927 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9928 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9929 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9930 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9931 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9932 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9933 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9934 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 9935 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9936 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9937 | "Content-Length: 5\r\n\r\n"; |
| 9938 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9939 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9940 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9941 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9942 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9943 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9944 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9945 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9946 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9947 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9948 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9949 | }; |
| 9950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9951 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9952 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9953 | // Negotiate SPDY to the proxy |
| 9954 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9955 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9957 | // Vanilla SSL to the server |
| 9958 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9959 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9960 | |
| 9961 | TestCompletionCallback callback1; |
| 9962 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9963 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9964 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9965 | |
| 9966 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9968 | |
| 9969 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9970 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9971 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9972 | log.GetEntries(&entries); |
| 9973 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9974 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9975 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9976 | ExpectLogContainsSomewhere( |
| 9977 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9978 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9979 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9980 | |
| 9981 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9982 | ASSERT_TRUE(response); |
| 9983 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9984 | EXPECT_EQ(407, response->headers->response_code()); |
| 9985 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 9986 | EXPECT_TRUE(response->auth_challenge.has_value()); |
| 9987 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9988 | |
| 9989 | TestCompletionCallback callback2; |
| 9990 | |
| 9991 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9992 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9994 | |
| 9995 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9997 | |
| 9998 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9999 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10000 | |
| 10001 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10002 | EXPECT_EQ(200, response->headers->response_code()); |
| 10003 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10004 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10005 | |
| 10006 | // The password prompt info should not be set. |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 10007 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10008 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10009 | LoadTimingInfo load_timing_info; |
| 10010 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10011 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10012 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10013 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10014 | trans.reset(); |
| 10015 | session->CloseAllConnections(); |
| 10016 | } |
| 10017 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10018 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10019 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10020 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10021 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10022 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10023 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10024 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10025 | HttpRequestInfo request; |
| 10026 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10027 | request.traffic_annotation = |
| 10028 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10029 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10031 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10032 | push_request.method = "GET"; |
| 10033 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10034 | push_request.traffic_annotation = |
| 10035 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10036 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10037 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10038 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10039 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10040 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10041 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10042 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10043 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10044 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10045 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10046 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10048 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10049 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10050 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10051 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10052 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10053 | |
| 10054 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10055 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10056 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10057 | }; |
| 10058 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10059 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10060 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10061 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10062 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10063 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10064 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10065 | spdy::SpdySerializedFrame stream1_body( |
| 10066 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10067 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10068 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10069 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10070 | |
| 10071 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10072 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10073 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10074 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10075 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10076 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10077 | }; |
| 10078 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10079 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10080 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10081 | // Negotiate SPDY to the proxy |
| 10082 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10083 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10084 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10085 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10086 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10087 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10088 | TestCompletionCallback callback; |
| 10089 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10091 | |
| 10092 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10094 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10095 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10096 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10097 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10098 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10100 | |
| 10101 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10102 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10103 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10104 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10105 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10106 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10107 | |
| 10108 | EXPECT_EQ(200, response->headers->response_code()); |
| 10109 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10110 | |
| 10111 | std::string response_data; |
| 10112 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10114 | EXPECT_EQ("hello!", response_data); |
| 10115 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10116 | LoadTimingInfo load_timing_info; |
| 10117 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10118 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10119 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10120 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10121 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10122 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10123 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10124 | |
| 10125 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10126 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10127 | EXPECT_EQ("pushed", response_data); |
| 10128 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10129 | LoadTimingInfo push_load_timing_info; |
| 10130 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10131 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10132 | // The transactions should share a socket ID, despite being for different |
| 10133 | // origins. |
| 10134 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10135 | push_load_timing_info.socket_log_id); |
| 10136 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10137 | trans.reset(); |
| 10138 | push_trans.reset(); |
| 10139 | session->CloseAllConnections(); |
| 10140 | } |
| 10141 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10142 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10143 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10144 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10145 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10146 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10147 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10148 | HttpRequestInfo request; |
| 10149 | |
| 10150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10151 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10152 | request.traffic_annotation = |
| 10153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10154 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10155 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10156 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10157 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10158 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10159 | |
| 10160 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10161 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10162 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10163 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10164 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10165 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10166 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10167 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10168 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10169 | spdy::SpdySerializedFrame push_rst( |
| 10170 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10171 | |
| 10172 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10173 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10174 | }; |
| 10175 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10176 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10177 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10178 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10179 | spdy::SpdySerializedFrame stream1_body( |
| 10180 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10181 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10182 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 10183 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10184 | |
| 10185 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10186 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10187 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10188 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10189 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10190 | }; |
| 10191 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10192 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10193 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10194 | // Negotiate SPDY to the proxy |
| 10195 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10196 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10197 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10198 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10199 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10200 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10201 | TestCompletionCallback callback; |
| 10202 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10204 | |
| 10205 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10207 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10208 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10209 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10210 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10211 | |
| 10212 | EXPECT_EQ(200, response->headers->response_code()); |
| 10213 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10214 | |
| 10215 | std::string response_data; |
| 10216 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10218 | EXPECT_EQ("hello!", response_data); |
| 10219 | |
| 10220 | trans.reset(); |
| 10221 | session->CloseAllConnections(); |
| 10222 | } |
| 10223 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10224 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10225 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10226 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10227 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10228 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10229 | proxy_delegate->set_trusted_spdy_proxy( |
| 10230 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10231 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10232 | HttpRequestInfo request; |
| 10233 | |
| 10234 | request.method = "GET"; |
| 10235 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10236 | request.traffic_annotation = |
| 10237 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10238 | |
| 10239 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10240 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10241 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10242 | BoundTestNetLog log; |
| 10243 | session_deps_.net_log = log.bound().net_log(); |
| 10244 | |
| 10245 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10246 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10247 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10250 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10251 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10252 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10253 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10254 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10255 | |
| 10256 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10257 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10258 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10259 | }; |
| 10260 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10261 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10262 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10263 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10264 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10265 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10266 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10267 | spdy::SpdySerializedFrame stream1_body( |
| 10268 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10269 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10270 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10271 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10272 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10273 | spdy::SpdySerializedFrame stream2_body( |
| 10274 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10275 | |
| 10276 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10277 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10278 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10279 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10280 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10281 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10282 | }; |
| 10283 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10284 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10285 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10286 | // Negotiate SPDY to the proxy |
| 10287 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10288 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10290 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10291 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10292 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10293 | TestCompletionCallback callback; |
| 10294 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10295 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10296 | |
| 10297 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10298 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10300 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10301 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10302 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10303 | |
| 10304 | EXPECT_EQ(200, response->headers->response_code()); |
| 10305 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10306 | |
| 10307 | std::string response_data; |
| 10308 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10309 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10310 | EXPECT_EQ("hello!", response_data); |
| 10311 | |
| 10312 | trans.reset(); |
| 10313 | session->CloseAllConnections(); |
| 10314 | } |
| 10315 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10316 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10317 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10318 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10319 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10320 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10321 | |
| 10322 | HttpRequestInfo request; |
| 10323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10324 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10325 | request.traffic_annotation = |
| 10326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10327 | |
| 10328 | // Attempt to fetch the URL from a server with a bad cert |
| 10329 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10330 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10331 | "Host: www.example.org:443\r\n" |
| 10332 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10333 | }; |
| 10334 | |
| 10335 | MockRead bad_cert_reads[] = { |
| 10336 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10337 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10338 | }; |
| 10339 | |
| 10340 | // Attempt to fetch the URL with a good cert |
| 10341 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10342 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10343 | "Host: www.example.org:443\r\n" |
| 10344 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10345 | MockWrite("GET / HTTP/1.1\r\n" |
| 10346 | "Host: www.example.org\r\n" |
| 10347 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10348 | }; |
| 10349 | |
| 10350 | MockRead good_cert_reads[] = { |
| 10351 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10352 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10354 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10355 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10356 | }; |
| 10357 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10358 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10359 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10360 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10361 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10362 | |
| 10363 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10365 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10367 | |
| 10368 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10370 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10373 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10380 | |
| 10381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10382 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10384 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10386 | |
| 10387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10388 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10390 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10391 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10392 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10393 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10394 | } |
| 10395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10396 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10397 | HttpRequestInfo request; |
| 10398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10399 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10400 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10401 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10402 | request.traffic_annotation = |
| 10403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10407 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10408 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10409 | MockWrite( |
| 10410 | "GET / HTTP/1.1\r\n" |
| 10411 | "Host: www.example.org\r\n" |
| 10412 | "Connection: keep-alive\r\n" |
| 10413 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10414 | }; |
| 10415 | |
| 10416 | // Lastly, the server responds with the actual content. |
| 10417 | MockRead data_reads[] = { |
| 10418 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10420 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10422 | }; |
| 10423 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10424 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10427 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10429 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10431 | |
| 10432 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10434 | } |
| 10435 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10436 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10437 | // Test user agent values, used both for the request header of the original |
| 10438 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10439 | // no request header / no HttpUserAgentSettings object. |
| 10440 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10441 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10442 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10443 | if (!setting_user_agent) { |
| 10444 | session_deps_.http_user_agent_settings.reset(); |
| 10445 | } else { |
| 10446 | session_deps_.http_user_agent_settings = |
| 10447 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10448 | std::string() /* accept-language */, setting_user_agent); |
| 10449 | } |
| 10450 | session_deps_.proxy_resolution_service = |
| 10451 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10452 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10454 | for (const char* request_user_agent : kTestUserAgents) { |
| 10455 | HttpRequestInfo request; |
| 10456 | request.method = "GET"; |
| 10457 | request.url = GURL("https://www.example.org/"); |
| 10458 | if (request_user_agent) { |
| 10459 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10460 | request_user_agent); |
| 10461 | } |
| 10462 | request.traffic_annotation = |
| 10463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10464 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10466 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10467 | std::string expected_request; |
| 10468 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10469 | expected_request = |
| 10470 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10471 | "Host: www.example.org:443\r\n" |
| 10472 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10473 | } else { |
| 10474 | expected_request = base::StringPrintf( |
| 10475 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10476 | "Host: www.example.org:443\r\n" |
| 10477 | "Proxy-Connection: keep-alive\r\n" |
| 10478 | "User-Agent: %s\r\n\r\n", |
| 10479 | setting_user_agent); |
| 10480 | } |
| 10481 | MockWrite data_writes[] = { |
| 10482 | MockWrite(expected_request.c_str()), |
| 10483 | }; |
| 10484 | MockRead data_reads[] = { |
| 10485 | // Return an error, so the transaction stops here (this test isn't |
| 10486 | // interested in the rest). |
| 10487 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10488 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10489 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10490 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10491 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10492 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10494 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10495 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10496 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10497 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10499 | |
| 10500 | rv = callback.WaitForResult(); |
| 10501 | EXPECT_THAT(rv, IsOk()); |
| 10502 | } |
| 10503 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10504 | } |
| 10505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10506 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10507 | HttpRequestInfo request; |
| 10508 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10509 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10510 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10511 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10512 | request.traffic_annotation = |
| 10513 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10517 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10518 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10519 | MockWrite( |
| 10520 | "GET / HTTP/1.1\r\n" |
| 10521 | "Host: www.example.org\r\n" |
| 10522 | "Connection: keep-alive\r\n" |
| 10523 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10524 | }; |
| 10525 | |
| 10526 | // Lastly, the server responds with the actual content. |
| 10527 | MockRead data_reads[] = { |
| 10528 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10530 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10531 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10532 | }; |
| 10533 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10534 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10535 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10537 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10538 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10539 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10541 | |
| 10542 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10544 | } |
| 10545 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10546 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10547 | HttpRequestInfo request; |
| 10548 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10549 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10550 | request.traffic_annotation = |
| 10551 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10555 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10556 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10557 | MockWrite( |
| 10558 | "POST / HTTP/1.1\r\n" |
| 10559 | "Host: www.example.org\r\n" |
| 10560 | "Connection: keep-alive\r\n" |
| 10561 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10562 | }; |
| 10563 | |
| 10564 | // Lastly, the server responds with the actual content. |
| 10565 | MockRead data_reads[] = { |
| 10566 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10567 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10568 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10569 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10570 | }; |
| 10571 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10572 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10573 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10574 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10575 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10576 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10577 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10578 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10579 | |
| 10580 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10581 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10582 | } |
| 10583 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10584 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10585 | HttpRequestInfo request; |
| 10586 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10587 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10588 | request.traffic_annotation = |
| 10589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10593 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10594 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10595 | MockWrite( |
| 10596 | "PUT / HTTP/1.1\r\n" |
| 10597 | "Host: www.example.org\r\n" |
| 10598 | "Connection: keep-alive\r\n" |
| 10599 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10600 | }; |
| 10601 | |
| 10602 | // Lastly, the server responds with the actual content. |
| 10603 | MockRead data_reads[] = { |
| 10604 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10605 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10606 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10607 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10608 | }; |
| 10609 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10610 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10613 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10617 | |
| 10618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10619 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10620 | } |
| 10621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10622 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10623 | HttpRequestInfo request; |
| 10624 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10625 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10626 | request.traffic_annotation = |
| 10627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10628 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10629 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10630 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10631 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10632 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10633 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10634 | "Host: www.example.org\r\n" |
| 10635 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10636 | }; |
| 10637 | |
| 10638 | // Lastly, the server responds with the actual content. |
| 10639 | MockRead data_reads[] = { |
| 10640 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10641 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10642 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10643 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10644 | }; |
| 10645 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10646 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10649 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10651 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10653 | |
| 10654 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10655 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10656 | } |
| 10657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10658 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10659 | HttpRequestInfo request; |
| 10660 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10661 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10662 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10663 | request.traffic_annotation = |
| 10664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10665 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10666 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10667 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10668 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10669 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10670 | MockWrite( |
| 10671 | "GET / HTTP/1.1\r\n" |
| 10672 | "Host: www.example.org\r\n" |
| 10673 | "Connection: keep-alive\r\n" |
| 10674 | "Pragma: no-cache\r\n" |
| 10675 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10676 | }; |
| 10677 | |
| 10678 | // Lastly, the server responds with the actual content. |
| 10679 | MockRead data_reads[] = { |
| 10680 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10681 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10682 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10683 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10684 | }; |
| 10685 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10686 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10687 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10689 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10690 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10691 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10693 | |
| 10694 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10696 | } |
| 10697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10698 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10699 | HttpRequestInfo request; |
| 10700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10701 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10702 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10703 | request.traffic_annotation = |
| 10704 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10708 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10709 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10710 | MockWrite( |
| 10711 | "GET / HTTP/1.1\r\n" |
| 10712 | "Host: www.example.org\r\n" |
| 10713 | "Connection: keep-alive\r\n" |
| 10714 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10715 | }; |
| 10716 | |
| 10717 | // Lastly, the server responds with the actual content. |
| 10718 | MockRead data_reads[] = { |
| 10719 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10720 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10721 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10722 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10723 | }; |
| 10724 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10725 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10726 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10728 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10729 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10730 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10732 | |
| 10733 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10734 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10735 | } |
| 10736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10737 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10738 | HttpRequestInfo request; |
| 10739 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10740 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10741 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10742 | request.traffic_annotation = |
| 10743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10744 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10747 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10748 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10749 | MockWrite( |
| 10750 | "GET / HTTP/1.1\r\n" |
| 10751 | "Host: www.example.org\r\n" |
| 10752 | "Connection: keep-alive\r\n" |
| 10753 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10754 | }; |
| 10755 | |
| 10756 | // Lastly, the server responds with the actual content. |
| 10757 | MockRead data_reads[] = { |
| 10758 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10759 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10760 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10761 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10762 | }; |
| 10763 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10764 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10765 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10766 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10767 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10768 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10769 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10770 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10771 | |
| 10772 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10773 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10774 | } |
| 10775 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10776 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10777 | HttpRequestInfo request; |
| 10778 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10779 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10780 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10781 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10782 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10783 | request.traffic_annotation = |
| 10784 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10788 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10789 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10790 | MockWrite( |
| 10791 | "GET / HTTP/1.1\r\n" |
| 10792 | "Host: www.example.org\r\n" |
| 10793 | "Connection: keep-alive\r\n" |
| 10794 | "referer: www.foo.com\r\n" |
| 10795 | "hEllo: Kitty\r\n" |
| 10796 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10797 | }; |
| 10798 | |
| 10799 | // Lastly, the server responds with the actual content. |
| 10800 | MockRead data_reads[] = { |
| 10801 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10802 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10803 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10805 | }; |
| 10806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10807 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10810 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10814 | |
| 10815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10817 | } |
| 10818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10819 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10820 | HttpRequestInfo request; |
| 10821 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10822 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10823 | request.traffic_annotation = |
| 10824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10825 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10826 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10827 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10828 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10829 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10830 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10833 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10834 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10835 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10836 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10837 | |
| 10838 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10839 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10840 | MockWrite("GET / HTTP/1.1\r\n" |
| 10841 | "Host: www.example.org\r\n" |
| 10842 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10843 | |
| 10844 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10845 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10846 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10848 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10849 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10850 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10852 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10853 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10854 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10855 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10856 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10857 | |
| 10858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10859 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10861 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10862 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10863 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10864 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10865 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10866 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10867 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10868 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10869 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10870 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10871 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10873 | EXPECT_EQ("Payload", response_text); |
| 10874 | } |
| 10875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10876 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10877 | HttpRequestInfo request; |
| 10878 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10879 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10880 | request.traffic_annotation = |
| 10881 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10882 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10883 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10884 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10885 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10886 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10887 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10891 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10892 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10893 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10894 | |
| 10895 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10896 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10897 | base::size(write_buffer)), |
| 10898 | MockWrite("GET / HTTP/1.1\r\n" |
| 10899 | "Host: www.example.org\r\n" |
| 10900 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10901 | |
| 10902 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10903 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10904 | base::size(read_buffer)), |
| 10905 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10906 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10907 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10909 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10910 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10911 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10912 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10915 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10916 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10917 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10919 | |
| 10920 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10921 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10922 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10923 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10924 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10925 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10926 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10929 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10930 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10931 | |
| 10932 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10933 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10935 | EXPECT_EQ("Payload", response_text); |
| 10936 | } |
| 10937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10938 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10939 | HttpRequestInfo request; |
| 10940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10941 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10942 | request.traffic_annotation = |
| 10943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10944 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10945 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10946 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10947 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10948 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10949 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10952 | |
| 10953 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10954 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10955 | |
| 10956 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10957 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10958 | MockWrite("GET / HTTP/1.1\r\n" |
| 10959 | "Host: www.example.org\r\n" |
| 10960 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10961 | |
| 10962 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10963 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10964 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10965 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10966 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10967 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10968 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10969 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10970 | |
| 10971 | TestCompletionCallback callback; |
| 10972 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10973 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10975 | |
| 10976 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10977 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10979 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10980 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10981 | |
| 10982 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10983 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10984 | TestLoadTimingNotReused(load_timing_info, |
| 10985 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10986 | |
| 10987 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10988 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10990 | EXPECT_EQ("Payload", response_text); |
| 10991 | } |
| 10992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10993 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10994 | HttpRequestInfo request; |
| 10995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10996 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10997 | request.traffic_annotation = |
| 10998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10999 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11000 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11001 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11002 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11003 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11004 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11005 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11007 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11008 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11009 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11010 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11011 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11012 | 0x05, // Version |
| 11013 | 0x01, // Command (CONNECT) |
| 11014 | 0x00, // Reserved. |
| 11015 | 0x03, // Address type (DOMAINNAME). |
| 11016 | 0x0F, // Length of domain (15) |
| 11017 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11018 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11019 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11020 | const char kSOCKS5OkResponse[] = |
| 11021 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11022 | |
| 11023 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11024 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11025 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11026 | MockWrite("GET / HTTP/1.1\r\n" |
| 11027 | "Host: www.example.org\r\n" |
| 11028 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11029 | |
| 11030 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11031 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11032 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11033 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11034 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11035 | MockRead("Payload"), |
| 11036 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11037 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11038 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11041 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11045 | |
| 11046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11050 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11051 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11052 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11053 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11054 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11055 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11056 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11057 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11058 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11059 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11060 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11061 | EXPECT_EQ("Payload", response_text); |
| 11062 | } |
| 11063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11064 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11065 | HttpRequestInfo request; |
| 11066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11067 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11068 | request.traffic_annotation = |
| 11069 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11070 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11071 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11072 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11073 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11074 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11075 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11079 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11080 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11081 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11082 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11083 | 0x05, // Version |
| 11084 | 0x01, // Command (CONNECT) |
| 11085 | 0x00, // Reserved. |
| 11086 | 0x03, // Address type (DOMAINNAME). |
| 11087 | 0x0F, // Length of domain (15) |
| 11088 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11089 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11090 | }; |
| 11091 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11092 | const char kSOCKS5OkResponse[] = |
| 11093 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11094 | |
| 11095 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11096 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11097 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11098 | base::size(kSOCKS5OkRequest)), |
| 11099 | MockWrite("GET / HTTP/1.1\r\n" |
| 11100 | "Host: www.example.org\r\n" |
| 11101 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11102 | |
| 11103 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11104 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11105 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11106 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11107 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11108 | MockRead("Payload"), |
| 11109 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11110 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11111 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11113 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11114 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11117 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11121 | |
| 11122 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11125 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11126 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11127 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11128 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11129 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11130 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11131 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11132 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11133 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11134 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11135 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11137 | EXPECT_EQ("Payload", response_text); |
| 11138 | } |
| 11139 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11140 | namespace { |
| 11141 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11142 | // Tests that for connection endpoints the group ids are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11143 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11144 | struct GroupIdTest { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11145 | std::string proxy_server; |
| 11146 | std::string url; |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11147 | ClientSocketPool::GroupId expected_group_id; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11148 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11149 | }; |
| 11150 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11151 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupIdTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11152 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11154 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11155 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11156 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11157 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11158 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11159 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11160 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11161 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11162 | |
| 11163 | return session; |
| 11164 | } |
| 11165 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11166 | int GroupIdTransactionHelper(const std::string& url, |
| 11167 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11168 | HttpRequestInfo request; |
| 11169 | request.method = "GET"; |
| 11170 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11171 | request.traffic_annotation = |
| 11172 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11174 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11176 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11177 | |
| 11178 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11179 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11180 | } |
| 11181 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11182 | } // namespace |
| 11183 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11184 | TEST_F(HttpNetworkTransactionTest, GroupIdForDirectConnections) { |
| 11185 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11186 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11187 | "", // unused |
| 11188 | "http://www.example.org/direct", |
| 11189 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11190 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11191 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11192 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11193 | }, |
| 11194 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11195 | "", // unused |
| 11196 | "http://[2001:1418:13:1::25]/direct", |
| 11197 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 80), |
| 11198 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11199 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11200 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11201 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11202 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11203 | // SSL Tests |
| 11204 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11205 | "", // unused |
| 11206 | "https://www.example.org/direct_ssl", |
| 11207 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11208 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11209 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11210 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11211 | }, |
| 11212 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11213 | "", // unused |
| 11214 | "https://[2001:1418:13:1::25]/direct", |
| 11215 | ClientSocketPool::GroupId(HostPortPair("2001:1418:13:1::25", 443), |
| 11216 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11217 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11218 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11219 | }, |
| 11220 | { |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11221 | "", // unused |
| 11222 | "https://host.with.alternate/direct", |
| 11223 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11224 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11225 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11226 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11227 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11228 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11229 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11230 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11231 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11232 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11233 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11234 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11235 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11236 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11237 | HttpNetworkSessionPeer peer(session.get()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11238 | CaptureGroupIdTransportSocketPool* transport_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11239 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11240 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11241 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11242 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11243 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11244 | |
| 11245 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11246 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11247 | EXPECT_EQ(tests[i].expected_group_id, |
| 11248 | transport_conn_pool->last_group_id_received()); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11249 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11250 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11251 | } |
| 11252 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11253 | TEST_F(HttpNetworkTransactionTest, GroupIdForHTTPProxyConnections) { |
| 11254 | const GroupIdTest tests[] = { |
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 | "http://www.example.org/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11258 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11259 | ClientSocketPool::SocketType::kHttp, |
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 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11264 | // SSL Tests |
| 11265 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11266 | "http_proxy", |
| 11267 | "https://www.example.org/http_connect_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11268 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11269 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11270 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11271 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11272 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11273 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11274 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11275 | "http_proxy", |
| 11276 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11277 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11278 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11279 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11280 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11281 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11282 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11283 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11284 | "http_proxy", |
| 11285 | "ftp://ftp.google.com/http_proxy_normal", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11286 | ClientSocketPool::GroupId(HostPortPair("ftp.google.com", 21), |
| 11287 | ClientSocketPool::SocketType::kFtp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11288 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11289 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11290 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11291 | }; |
| 11292 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11293 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11294 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11295 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11296 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11297 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11298 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11299 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11300 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11301 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11302 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11303 | HostPortPair("http_proxy", 80)); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11304 | CaptureGroupIdTransportSocketPool* http_proxy_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11305 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11306 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11307 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11308 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11309 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11310 | |
| 11311 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11312 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11313 | EXPECT_EQ(tests[i].expected_group_id, |
| 11314 | http_proxy_pool->last_group_id_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11315 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11316 | } |
| 11317 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11318 | TEST_F(HttpNetworkTransactionTest, GroupIdForSOCKSConnections) { |
| 11319 | const GroupIdTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11320 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11321 | "socks4://socks_proxy:1080", |
| 11322 | "http://www.example.org/socks4_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11323 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11324 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11325 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11326 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11327 | }, |
| 11328 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11329 | "socks5://socks_proxy:1080", |
| 11330 | "http://www.example.org/socks5_direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11331 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 80), |
| 11332 | ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11333 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11334 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11335 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11336 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11337 | // SSL Tests |
| 11338 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11339 | "socks4://socks_proxy:1080", |
| 11340 | "https://www.example.org/socks4_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11341 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11342 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11343 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11344 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11345 | }, |
| 11346 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11347 | "socks5://socks_proxy:1080", |
| 11348 | "https://www.example.org/socks5_ssl", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11349 | ClientSocketPool::GroupId(HostPortPair("www.example.org", 443), |
| 11350 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11351 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11352 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11353 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11354 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11355 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11356 | "socks4://socks_proxy:1080", |
| 11357 | "https://host.with.alternate/direct", |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11358 | ClientSocketPool::GroupId(HostPortPair("host.with.alternate", 443), |
| 11359 | ClientSocketPool::SocketType::kSsl, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 11360 | PrivacyMode::PRIVACY_MODE_DISABLED), |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11361 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11362 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11363 | }; |
| 11364 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11365 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11366 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11367 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11368 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11369 | std::unique_ptr<HttpNetworkSession> session( |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11370 | SetupSessionForGroupIdTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11371 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11372 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11373 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11374 | ProxyServer proxy_server( |
| 11375 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11376 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11377 | CaptureGroupIdTransportSocketPool* socks_conn_pool = |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 11378 | new CaptureGroupIdTransportSocketPool(&dummy_connect_job_params_); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11379 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11380 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11381 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11382 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11384 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11385 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11386 | EXPECT_EQ(ERR_IO_PENDING, |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 11387 | GroupIdTransactionHelper(tests[i].url, session.get())); |
| 11388 | EXPECT_EQ(tests[i].expected_group_id, |
| 11389 | socks_conn_pool->last_group_id_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11390 | } |
| 11391 | } |
| 11392 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11393 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11394 | HttpRequestInfo request; |
| 11395 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11396 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11397 | request.traffic_annotation = |
| 11398 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11399 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11400 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11401 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11402 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11403 | // This simulates failure resolving all hostnames; that means we will fail |
| 11404 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11405 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11406 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11410 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11412 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11414 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11415 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11416 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11417 | } |
| 11418 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11419 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11420 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11421 | HttpRequestInfo request; |
| 11422 | request.method = "GET"; |
| 11423 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11424 | request.traffic_annotation = |
| 11425 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11426 | |
| 11427 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11428 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11429 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11430 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11431 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11432 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11434 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11436 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11437 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11438 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11440 | |
| 11441 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11442 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11443 | |
| 11444 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11445 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11446 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11447 | } |
| 11448 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11449 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11450 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11451 | HttpRequestInfo request; |
| 11452 | request.method = "GET"; |
| 11453 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11454 | request.traffic_annotation = |
| 11455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11456 | |
| 11457 | MockRead data_reads[] = { |
| 11458 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11459 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11460 | }; |
| 11461 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11462 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11463 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11466 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11470 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11472 | |
| 11473 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11474 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11475 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11476 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11477 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11478 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11479 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11480 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11481 | |
| 11482 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11483 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11484 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11485 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11486 | |
| 11487 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11488 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11489 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11490 | } |
| 11491 | |
| 11492 | // Make sure that a dropped connection while draining the body for auth |
| 11493 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11494 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11495 | HttpRequestInfo request; |
| 11496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11497 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11498 | request.traffic_annotation = |
| 11499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11500 | |
| 11501 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11502 | MockWrite( |
| 11503 | "GET / HTTP/1.1\r\n" |
| 11504 | "Host: www.example.org\r\n" |
| 11505 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11506 | }; |
| 11507 | |
| 11508 | MockRead data_reads1[] = { |
| 11509 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11510 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11511 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11512 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11513 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11514 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11515 | }; |
| 11516 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11517 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11518 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11520 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11521 | // be issuing -- the final header line contains the credentials. |
| 11522 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11523 | MockWrite( |
| 11524 | "GET / HTTP/1.1\r\n" |
| 11525 | "Host: www.example.org\r\n" |
| 11526 | "Connection: keep-alive\r\n" |
| 11527 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11528 | }; |
| 11529 | |
| 11530 | // Lastly, the server responds with the actual content. |
| 11531 | MockRead data_reads2[] = { |
| 11532 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11533 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11534 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11535 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11536 | }; |
| 11537 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11538 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11539 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11541 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11542 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11546 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11548 | |
| 11549 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11552 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11553 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11554 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11555 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11556 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11558 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11560 | |
| 11561 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11562 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11563 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11564 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11565 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11566 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11567 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11568 | } |
| 11569 | |
| 11570 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11571 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11572 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11573 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11574 | |
| 11575 | HttpRequestInfo request; |
| 11576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11577 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11578 | request.traffic_annotation = |
| 11579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11580 | |
| 11581 | MockRead proxy_reads[] = { |
| 11582 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11583 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11584 | }; |
| 11585 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11586 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11587 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11588 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11589 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11591 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11592 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11593 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11594 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11595 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11597 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11598 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11599 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11601 | |
| 11602 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11603 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11604 | } |
| 11605 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11606 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11607 | HttpRequestInfo request; |
| 11608 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11609 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11610 | request.traffic_annotation = |
| 11611 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11614 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11615 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11616 | MockRead data_reads[] = { |
| 11617 | 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] | 11618 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11619 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11620 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11621 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11624 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11625 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11626 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11628 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11629 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11631 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11632 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11633 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11634 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11635 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11636 | |
| 11637 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11638 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11639 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11640 | } |
| 11641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11642 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11643 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11644 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11645 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11646 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11647 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11649 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11650 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11651 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11652 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11653 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11654 | |
| 11655 | HttpRequestInfo request; |
| 11656 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11657 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11658 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11659 | request.traffic_annotation = |
| 11660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11664 | |
| 11665 | MockRead data_reads[] = { |
| 11666 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11667 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11668 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11669 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11670 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11672 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11673 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11675 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11677 | |
| 11678 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11679 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11681 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11682 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11683 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11684 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11685 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11686 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11687 | } |
| 11688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11689 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11690 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11691 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11692 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11693 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11694 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11695 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11696 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11697 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11698 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11699 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11700 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11701 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11702 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11703 | |
| 11704 | HttpRequestInfo request; |
| 11705 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11706 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11707 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11708 | request.traffic_annotation = |
| 11709 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11710 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11711 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11713 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11714 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11715 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11716 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11718 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11719 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11720 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11722 | |
| 11723 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11724 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11725 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11726 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11727 | } |
| 11728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11729 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11730 | class FakeUploadElementReader : public UploadElementReader { |
| 11731 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11732 | FakeUploadElementReader() = default; |
| 11733 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11734 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11735 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11736 | |
| 11737 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11738 | int Init(CompletionOnceCallback callback) override { |
| 11739 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11740 | return ERR_IO_PENDING; |
| 11741 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11742 | uint64_t GetContentLength() const override { return 0; } |
| 11743 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11744 | int Read(IOBuffer* buf, |
| 11745 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11746 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11747 | return ERR_FAILED; |
| 11748 | } |
| 11749 | |
| 11750 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11751 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11752 | }; |
| 11753 | |
| 11754 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11755 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11756 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11757 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11758 | |
| 11759 | HttpRequestInfo request; |
| 11760 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11761 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11762 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11763 | request.traffic_annotation = |
| 11764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11767 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11768 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11769 | |
| 11770 | StaticSocketDataProvider data; |
| 11771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11772 | |
| 11773 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11774 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11775 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11776 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11777 | |
| 11778 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11779 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11780 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11781 | |
| 11782 | // Return Init()'s result after the transaction gets destroyed. |
| 11783 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11784 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11785 | } |
| 11786 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11787 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11788 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11789 | HttpRequestInfo request; |
| 11790 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11791 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11792 | request.traffic_annotation = |
| 11793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11794 | |
| 11795 | // First transaction will request a resource and receive a Basic challenge |
| 11796 | // with realm="first_realm". |
| 11797 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11798 | MockWrite( |
| 11799 | "GET / HTTP/1.1\r\n" |
| 11800 | "Host: www.example.org\r\n" |
| 11801 | "Connection: keep-alive\r\n" |
| 11802 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11803 | }; |
| 11804 | MockRead data_reads1[] = { |
| 11805 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11806 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11807 | "\r\n"), |
| 11808 | }; |
| 11809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11810 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11811 | // for first_realm. The server will reject and provide a challenge with |
| 11812 | // second_realm. |
| 11813 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11814 | MockWrite( |
| 11815 | "GET / HTTP/1.1\r\n" |
| 11816 | "Host: www.example.org\r\n" |
| 11817 | "Connection: keep-alive\r\n" |
| 11818 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11819 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11820 | }; |
| 11821 | MockRead data_reads2[] = { |
| 11822 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11823 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11824 | "\r\n"), |
| 11825 | }; |
| 11826 | |
| 11827 | // This again fails, and goes back to first_realm. Make sure that the |
| 11828 | // entry is removed from cache. |
| 11829 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11830 | MockWrite( |
| 11831 | "GET / HTTP/1.1\r\n" |
| 11832 | "Host: www.example.org\r\n" |
| 11833 | "Connection: keep-alive\r\n" |
| 11834 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11835 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11836 | }; |
| 11837 | MockRead data_reads3[] = { |
| 11838 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11839 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11840 | "\r\n"), |
| 11841 | }; |
| 11842 | |
| 11843 | // Try one last time (with the correct password) and get the resource. |
| 11844 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11845 | MockWrite( |
| 11846 | "GET / HTTP/1.1\r\n" |
| 11847 | "Host: www.example.org\r\n" |
| 11848 | "Connection: keep-alive\r\n" |
| 11849 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11850 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11851 | }; |
| 11852 | MockRead data_reads4[] = { |
| 11853 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11854 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11855 | "Content-Length: 5\r\n" |
| 11856 | "\r\n" |
| 11857 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11858 | }; |
| 11859 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11860 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11861 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11862 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11863 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11864 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11865 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11866 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11867 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11869 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11870 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11871 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11873 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11874 | // Issue the first request with Authorize headers. There should be a |
| 11875 | // password prompt for first_realm waiting to be filled in after the |
| 11876 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11877 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11879 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11880 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11881 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11882 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11883 | base::Optional<AuthChallengeInfo> challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11884 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11885 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11886 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11887 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11888 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11889 | |
| 11890 | // Issue the second request with an incorrect password. There should be a |
| 11891 | // password prompt for second_realm waiting to be filled in after the |
| 11892 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11893 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11894 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11895 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11897 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11898 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11899 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11900 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11901 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11902 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11903 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11904 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11905 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11906 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11907 | |
| 11908 | // Issue the third request with another incorrect password. There should be |
| 11909 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11910 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11911 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11912 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11913 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11914 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11916 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11917 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11918 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11919 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11920 | challenge = response->auth_challenge; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11921 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11922 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11923 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11924 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11925 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11926 | |
| 11927 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11928 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11929 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11930 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11932 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11933 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11934 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11935 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 11936 | EXPECT_FALSE(response->auth_challenge.has_value()); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11937 | } |
| 11938 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11939 | // Regression test for https://crbug.com/754395. |
| 11940 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11941 | MockRead data_reads[] = { |
| 11942 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11943 | MockRead(kAlternativeServiceHttpHeader), |
| 11944 | MockRead("\r\n"), |
| 11945 | MockRead("hello world"), |
| 11946 | MockRead(SYNCHRONOUS, OK), |
| 11947 | }; |
| 11948 | |
| 11949 | HttpRequestInfo request; |
| 11950 | request.method = "GET"; |
| 11951 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11952 | request.traffic_annotation = |
| 11953 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11954 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11955 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11957 | |
| 11958 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11959 | ssl.ssl_info.cert = |
| 11960 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11961 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11962 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11964 | |
| 11965 | TestCompletionCallback callback; |
| 11966 | |
| 11967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11968 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11969 | |
| 11970 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11972 | |
| 11973 | url::SchemeHostPort test_server(request.url); |
| 11974 | HttpServerProperties* http_server_properties = |
| 11975 | session->http_server_properties(); |
| 11976 | EXPECT_TRUE( |
| 11977 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11978 | |
| 11979 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11980 | |
| 11981 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11982 | ASSERT_TRUE(response); |
| 11983 | ASSERT_TRUE(response->headers); |
| 11984 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11985 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11986 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11987 | |
| 11988 | std::string response_data; |
| 11989 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11990 | EXPECT_EQ("hello world", response_data); |
| 11991 | |
| 11992 | EXPECT_TRUE( |
| 11993 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11994 | } |
| 11995 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11996 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11997 | MockRead data_reads[] = { |
| 11998 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11999 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12000 | MockRead("\r\n"), |
| 12001 | MockRead("hello world"), |
| 12002 | MockRead(SYNCHRONOUS, OK), |
| 12003 | }; |
| 12004 | |
| 12005 | HttpRequestInfo request; |
| 12006 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12007 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12008 | request.traffic_annotation = |
| 12009 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12011 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12012 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12013 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12014 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12015 | ssl.ssl_info.cert = |
| 12016 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12017 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12019 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12020 | TestCompletionCallback callback; |
| 12021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12023 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12024 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12025 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12027 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12028 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12029 | HttpServerProperties* http_server_properties = |
| 12030 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12031 | EXPECT_TRUE( |
| 12032 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12033 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12034 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12036 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12037 | ASSERT_TRUE(response); |
| 12038 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12039 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12040 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12041 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12042 | |
| 12043 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12044 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12045 | EXPECT_EQ("hello world", response_data); |
| 12046 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12047 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12048 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12049 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12050 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12051 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12052 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12053 | } |
| 12054 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12055 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12056 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12057 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12058 | MockRead data_reads[] = { |
| 12059 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12060 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12061 | MockRead("\r\n"), |
| 12062 | MockRead("hello world"), |
| 12063 | MockRead(SYNCHRONOUS, OK), |
| 12064 | }; |
| 12065 | |
| 12066 | HttpRequestInfo request; |
| 12067 | request.method = "GET"; |
| 12068 | request.url = GURL("http://www.example.org/"); |
| 12069 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12070 | request.traffic_annotation = |
| 12071 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12072 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12073 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12075 | |
| 12076 | TestCompletionCallback callback; |
| 12077 | |
| 12078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12080 | |
| 12081 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12082 | HttpServerProperties* http_server_properties = |
| 12083 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12084 | EXPECT_TRUE( |
| 12085 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12086 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12087 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12089 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12091 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12092 | ASSERT_TRUE(response); |
| 12093 | ASSERT_TRUE(response->headers); |
| 12094 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12095 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12096 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12097 | |
| 12098 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12099 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12100 | EXPECT_EQ("hello world", response_data); |
| 12101 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12102 | EXPECT_TRUE( |
| 12103 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12104 | } |
| 12105 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12106 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12107 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12108 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12109 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12110 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12111 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12112 | HttpRequestInfo request; |
| 12113 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12114 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12115 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12116 | request.traffic_annotation = |
| 12117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12118 | |
| 12119 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12120 | StaticSocketDataProvider first_data; |
| 12121 | first_data.set_connect_data(mock_connect); |
| 12122 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12123 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12124 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12125 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12126 | |
| 12127 | MockRead data_reads[] = { |
| 12128 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12129 | MockRead(ASYNC, OK), |
| 12130 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12131 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12132 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12133 | |
| 12134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12135 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12136 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12137 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12138 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12139 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12140 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12141 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12142 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12145 | TestCompletionCallback callback; |
| 12146 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12147 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12148 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12149 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12150 | } |
| 12151 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12152 | // Regression test for https://crbug.com/615497: |
| 12153 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12154 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12155 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12156 | HttpRequestInfo request; |
| 12157 | request.method = "GET"; |
| 12158 | request.url = GURL("http://www.example.org/"); |
| 12159 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12160 | request.traffic_annotation = |
| 12161 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12162 | |
| 12163 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12164 | StaticSocketDataProvider first_data; |
| 12165 | first_data.set_connect_data(mock_connect); |
| 12166 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12167 | |
| 12168 | MockRead data_reads[] = { |
| 12169 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12170 | MockRead(ASYNC, OK), |
| 12171 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12172 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12173 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12174 | |
| 12175 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12176 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12177 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12178 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12179 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12180 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12181 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12182 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12184 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12185 | TestCompletionCallback callback; |
| 12186 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12187 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12188 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12189 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12190 | } |
| 12191 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12192 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12193 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12195 | HttpServerProperties* http_server_properties = |
| 12196 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12197 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12198 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12199 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12200 | http_server_properties->SetQuicAlternativeService( |
| 12201 | test_server, alternative_service, expiration, |
| 12202 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12203 | EXPECT_EQ( |
| 12204 | 1u, |
| 12205 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12206 | |
| 12207 | // Send a clear header. |
| 12208 | MockRead data_reads[] = { |
| 12209 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12210 | MockRead("Alt-Svc: clear\r\n"), |
| 12211 | MockRead("\r\n"), |
| 12212 | MockRead("hello world"), |
| 12213 | MockRead(SYNCHRONOUS, OK), |
| 12214 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12215 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12216 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12217 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12218 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12219 | ssl.ssl_info.cert = |
| 12220 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12221 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12223 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12224 | HttpRequestInfo request; |
| 12225 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12226 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12227 | request.traffic_annotation = |
| 12228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12229 | |
| 12230 | TestCompletionCallback callback; |
| 12231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12233 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12234 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12235 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12237 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12238 | ASSERT_TRUE(response); |
| 12239 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12240 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12241 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12242 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12243 | |
| 12244 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12245 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12246 | EXPECT_EQ("hello world", response_data); |
| 12247 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12248 | EXPECT_TRUE( |
| 12249 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12250 | } |
| 12251 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12252 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12253 | MockRead data_reads[] = { |
| 12254 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12255 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12256 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12257 | MockRead("hello world"), |
| 12258 | MockRead(SYNCHRONOUS, OK), |
| 12259 | }; |
| 12260 | |
| 12261 | HttpRequestInfo request; |
| 12262 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12263 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12264 | request.traffic_annotation = |
| 12265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12266 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12267 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12269 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12270 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12271 | ssl.ssl_info.cert = |
| 12272 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12273 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12275 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12276 | TestCompletionCallback callback; |
| 12277 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12279 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12283 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12284 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12285 | HttpServerProperties* http_server_properties = |
| 12286 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12287 | EXPECT_TRUE( |
| 12288 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12289 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12290 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12292 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12293 | ASSERT_TRUE(response); |
| 12294 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12295 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12296 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12297 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12298 | |
| 12299 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12300 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12301 | EXPECT_EQ("hello world", response_data); |
| 12302 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12303 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12304 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12305 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12306 | |
| 12307 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12308 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12309 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12310 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12311 | 1234); |
| 12312 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12313 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12314 | } |
| 12315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12316 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12317 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12318 | HostPortPair alternative("alternative.example.org", 443); |
| 12319 | std::string origin_url = "https://origin.example.org:443"; |
| 12320 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12321 | |
| 12322 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12323 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12324 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12326 | |
| 12327 | // HTTP/1.1 data for request. |
| 12328 | MockWrite http_writes[] = { |
| 12329 | MockWrite("GET / HTTP/1.1\r\n" |
| 12330 | "Host: alternative.example.org\r\n" |
| 12331 | "Connection: keep-alive\r\n\r\n"), |
| 12332 | }; |
| 12333 | |
| 12334 | MockRead http_reads[] = { |
| 12335 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12336 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12337 | "Content-Length: 40\r\n\r\n" |
| 12338 | "first HTTP/1.1 response from alternative"), |
| 12339 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12340 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12341 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12342 | |
| 12343 | StaticSocketDataProvider data_refused; |
| 12344 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12345 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12346 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12347 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12349 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12350 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12351 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12352 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12353 | http_server_properties->SetQuicAlternativeService( |
| 12354 | server, alternative_service, expiration, |
| 12355 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12356 | // Mark the QUIC alternative service as broken. |
| 12357 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12358 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12359 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12360 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12361 | request.method = "GET"; |
| 12362 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12363 | request.traffic_annotation = |
| 12364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12365 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12366 | TestCompletionCallback callback; |
| 12367 | NetErrorDetails details; |
| 12368 | EXPECT_FALSE(details.quic_broken); |
| 12369 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12370 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12371 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12372 | EXPECT_TRUE(details.quic_broken); |
| 12373 | } |
| 12374 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12375 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12376 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12377 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12378 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12379 | std::string origin_url = "https://origin.example.org:443"; |
| 12380 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12381 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12382 | |
| 12383 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12384 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12385 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12387 | |
| 12388 | // HTTP/1.1 data for request. |
| 12389 | MockWrite http_writes[] = { |
| 12390 | MockWrite("GET / HTTP/1.1\r\n" |
| 12391 | "Host: alternative1.example.org\r\n" |
| 12392 | "Connection: keep-alive\r\n\r\n"), |
| 12393 | }; |
| 12394 | |
| 12395 | MockRead http_reads[] = { |
| 12396 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12397 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12398 | "Content-Length: 40\r\n\r\n" |
| 12399 | "first HTTP/1.1 response from alternative1"), |
| 12400 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12401 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12402 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12403 | |
| 12404 | StaticSocketDataProvider data_refused; |
| 12405 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12406 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12409 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12410 | session->http_server_properties(); |
| 12411 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12412 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12413 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12414 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12415 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12416 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12417 | alternative_service_info_vector.push_back( |
| 12418 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12419 | alternative_service1, expiration, |
| 12420 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12421 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12422 | alternative_service_info_vector.push_back( |
| 12423 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12424 | alternative_service2, expiration, |
| 12425 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12426 | |
| 12427 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12428 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12429 | |
| 12430 | // Mark one of the QUIC alternative service as broken. |
| 12431 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12432 | EXPECT_EQ(2u, |
| 12433 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12434 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12435 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12436 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12437 | request.method = "GET"; |
| 12438 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12439 | request.traffic_annotation = |
| 12440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12441 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12442 | TestCompletionCallback callback; |
| 12443 | NetErrorDetails details; |
| 12444 | EXPECT_FALSE(details.quic_broken); |
| 12445 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12446 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12447 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12448 | EXPECT_FALSE(details.quic_broken); |
| 12449 | } |
| 12450 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12451 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12452 | HttpRequestInfo request; |
| 12453 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12454 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12455 | request.traffic_annotation = |
| 12456 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12457 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12458 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12459 | StaticSocketDataProvider first_data; |
| 12460 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12461 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12462 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12463 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12464 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12465 | |
| 12466 | MockRead data_reads[] = { |
| 12467 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12468 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12469 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12470 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12471 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12472 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12475 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12476 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12477 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12478 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12479 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12480 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12481 | // Port is ignored by MockConnect anyway. |
| 12482 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12483 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12484 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12485 | http_server_properties->SetHttp2AlternativeService( |
| 12486 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12489 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12490 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12491 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12493 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12495 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12496 | ASSERT_TRUE(response); |
| 12497 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12498 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12499 | |
| 12500 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12501 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12502 | EXPECT_EQ("hello world", response_data); |
| 12503 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12504 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12505 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12506 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12507 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12508 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12509 | EXPECT_TRUE( |
| 12510 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12511 | } |
| 12512 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12513 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12514 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12515 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12516 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12517 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12518 | HttpRequestInfo restricted_port_request; |
| 12519 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12520 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12521 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12522 | restricted_port_request.traffic_annotation = |
| 12523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12524 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12525 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12526 | StaticSocketDataProvider first_data; |
| 12527 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12528 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12529 | |
| 12530 | MockRead data_reads[] = { |
| 12531 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12532 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12533 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12534 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12535 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12536 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12537 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12538 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12540 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12541 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12542 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12543 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12544 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12545 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12546 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12547 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12548 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12549 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12550 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12551 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12552 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12554 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12556 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12557 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12559 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12560 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12561 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12562 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12563 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12564 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12565 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12566 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12567 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12568 | |
| 12569 | HttpRequestInfo restricted_port_request; |
| 12570 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12571 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12572 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12573 | restricted_port_request.traffic_annotation = |
| 12574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12575 | |
| 12576 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12577 | StaticSocketDataProvider first_data; |
| 12578 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12579 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12580 | |
| 12581 | MockRead data_reads[] = { |
| 12582 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12583 | MockRead("hello world"), |
| 12584 | MockRead(ASYNC, OK), |
| 12585 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12586 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12587 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12588 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12589 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12593 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12594 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12595 | session->http_server_properties(); |
| 12596 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12597 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12598 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12599 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12600 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12601 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12602 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12605 | TestCompletionCallback callback; |
| 12606 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12607 | EXPECT_EQ(ERR_IO_PENDING, |
| 12608 | trans.Start(&restricted_port_request, callback.callback(), |
| 12609 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12610 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12611 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12612 | } |
| 12613 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12614 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12615 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12616 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12617 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12618 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12619 | HttpRequestInfo restricted_port_request; |
| 12620 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12621 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12622 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12623 | restricted_port_request.traffic_annotation = |
| 12624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12625 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12626 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12627 | StaticSocketDataProvider first_data; |
| 12628 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12629 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12630 | |
| 12631 | MockRead data_reads[] = { |
| 12632 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12633 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12634 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12635 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12636 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12637 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12638 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12639 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12640 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12643 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12644 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12645 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12646 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12647 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12648 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12649 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12650 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12651 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12652 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12654 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12655 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12656 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12657 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12658 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12660 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12661 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12662 | } |
| 12663 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12664 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12665 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12666 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12667 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12668 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12669 | HttpRequestInfo unrestricted_port_request; |
| 12670 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12671 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12672 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12673 | unrestricted_port_request.traffic_annotation = |
| 12674 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12675 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12676 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12677 | StaticSocketDataProvider first_data; |
| 12678 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12679 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12680 | |
| 12681 | MockRead data_reads[] = { |
| 12682 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12683 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12684 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12685 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12686 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12688 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12689 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12693 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12694 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12695 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12696 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12697 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12698 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12699 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12700 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12701 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12702 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12704 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12705 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12706 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12707 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12708 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12710 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12711 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12712 | } |
| 12713 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12714 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12715 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12716 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12717 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12718 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12719 | HttpRequestInfo unrestricted_port_request; |
| 12720 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12721 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12722 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12723 | unrestricted_port_request.traffic_annotation = |
| 12724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12725 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12726 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12727 | StaticSocketDataProvider first_data; |
| 12728 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12729 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12730 | |
| 12731 | MockRead data_reads[] = { |
| 12732 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12733 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12734 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12735 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12736 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12737 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12738 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12739 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12741 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12743 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12744 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12745 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12746 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12747 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12748 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12749 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12750 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12751 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12752 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12755 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12757 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12758 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12760 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12761 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12762 | } |
| 12763 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12764 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12765 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12766 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12767 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12768 | HttpRequestInfo request; |
| 12769 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12770 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12771 | request.traffic_annotation = |
| 12772 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12773 | |
| 12774 | // The alternate protocol request will error out before we attempt to connect, |
| 12775 | // so only the standard HTTP request will try to connect. |
| 12776 | MockRead data_reads[] = { |
| 12777 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12778 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12779 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12780 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12781 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12785 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12786 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12787 | session->http_server_properties(); |
| 12788 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12789 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12790 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12791 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12792 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12793 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12796 | TestCompletionCallback callback; |
| 12797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12800 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12801 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12804 | ASSERT_TRUE(response); |
| 12805 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12806 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12807 | |
| 12808 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12809 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12810 | EXPECT_EQ("hello world", response_data); |
| 12811 | } |
| 12812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12813 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12814 | HttpRequestInfo request; |
| 12815 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12816 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12817 | request.traffic_annotation = |
| 12818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12819 | |
| 12820 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12821 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12822 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12823 | MockRead("\r\n"), |
| 12824 | MockRead("hello world"), |
| 12825 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12826 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12827 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12828 | StaticSocketDataProvider first_transaction(data_reads, |
| 12829 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12830 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12831 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12832 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12833 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12834 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12835 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12836 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12837 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12838 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12839 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12840 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12841 | spdy::SpdySerializedFrame resp( |
| 12842 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12843 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12844 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12845 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12846 | }; |
| 12847 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12848 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12849 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12850 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12851 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12852 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12853 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12854 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12855 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12856 | &hanging_non_alternate_protocol_socket); |
| 12857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12858 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12859 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12860 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12861 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12862 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12864 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12866 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12867 | |
| 12868 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12869 | ASSERT_TRUE(response); |
| 12870 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12871 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12872 | |
| 12873 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12874 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12875 | EXPECT_EQ("hello world", response_data); |
| 12876 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12877 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12878 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12880 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12882 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12883 | |
| 12884 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12885 | ASSERT_TRUE(response); |
| 12886 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12887 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12888 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12889 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12890 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12891 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12892 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12893 | } |
| 12894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12895 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12896 | HttpRequestInfo request; |
| 12897 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12898 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12899 | request.traffic_annotation = |
| 12900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12901 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12902 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12903 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12904 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12905 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12906 | MockRead("\r\n"), |
| 12907 | MockRead("hello world"), |
| 12908 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12909 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12910 | }; |
| 12911 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12912 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12913 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12914 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12915 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12916 | ssl_http11.ssl_info.cert = |
| 12917 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12918 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12919 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12920 | |
| 12921 | // Second transaction starts an alternative and a non-alternative Job. |
| 12922 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12923 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12924 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12925 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12926 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12927 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12928 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12929 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12930 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12931 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12932 | // Third transaction starts an alternative and a non-alternative job. |
| 12933 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12934 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12935 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12936 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12937 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12938 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12939 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12940 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12941 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12942 | spdy::SpdySerializedFrame resp1( |
| 12943 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12944 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 12945 | spdy::SpdySerializedFrame resp2( |
| 12946 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12947 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12948 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12949 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12950 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12951 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12952 | }; |
| 12953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12954 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12955 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12956 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12957 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12959 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12960 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12961 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12962 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12963 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12964 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12965 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12966 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12967 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12969 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12970 | |
| 12971 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12972 | ASSERT_TRUE(response); |
| 12973 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12974 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12975 | |
| 12976 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12977 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12978 | EXPECT_EQ("hello world", response_data); |
| 12979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12980 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12981 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12982 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12985 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12986 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12987 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12989 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12990 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12991 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12992 | |
| 12993 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12994 | ASSERT_TRUE(response); |
| 12995 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12996 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12997 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12998 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12999 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13000 | EXPECT_EQ("hello!", response_data); |
| 13001 | |
| 13002 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13003 | ASSERT_TRUE(response); |
| 13004 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13005 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13006 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13007 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13008 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13009 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13010 | } |
| 13011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13012 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13013 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13014 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13015 | HttpRequestInfo request; |
| 13016 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13017 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13018 | request.traffic_annotation = |
| 13019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13020 | |
| 13021 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13022 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13023 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13024 | MockRead("\r\n"), |
| 13025 | MockRead("hello world"), |
| 13026 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13027 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13028 | }; |
| 13029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13030 | StaticSocketDataProvider first_transaction(data_reads, |
| 13031 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13032 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13033 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13034 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13035 | ssl.ssl_info.cert = |
| 13036 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13037 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13039 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13040 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13041 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13042 | hanging_alternate_protocol_socket.set_connect_data( |
| 13043 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13044 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13045 | &hanging_alternate_protocol_socket); |
| 13046 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13047 | // 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] | 13048 | StaticSocketDataProvider second_transaction(data_reads, |
| 13049 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13050 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13053 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13056 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13057 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13059 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13061 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13062 | |
| 13063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13064 | ASSERT_TRUE(response); |
| 13065 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13066 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13067 | |
| 13068 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13069 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13070 | EXPECT_EQ("hello world", response_data); |
| 13071 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13072 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13073 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13075 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13077 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13078 | |
| 13079 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13080 | ASSERT_TRUE(response); |
| 13081 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13082 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13083 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13084 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13085 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13086 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13087 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13088 | } |
| 13089 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13090 | // Test that proxy is resolved using the origin url, |
| 13091 | // regardless of the alternative server. |
| 13092 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13093 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13094 | ProxyConfig proxy_config; |
| 13095 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13096 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13097 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13098 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13099 | |
| 13100 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13101 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13102 | &capturing_proxy_resolver); |
| 13103 | |
| 13104 | TestNetLog net_log; |
| 13105 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13106 | session_deps_.proxy_resolution_service = |
| 13107 | std::make_unique<ProxyResolutionService>( |
| 13108 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13109 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13110 | |
| 13111 | session_deps_.net_log = &net_log; |
| 13112 | |
| 13113 | // Configure alternative service with a hostname that is not bypassed by the |
| 13114 | // proxy. |
| 13115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13116 | HttpServerProperties* http_server_properties = |
| 13117 | session->http_server_properties(); |
| 13118 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13119 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13120 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13121 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13122 | http_server_properties->SetHttp2AlternativeService( |
| 13123 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13124 | |
| 13125 | // Non-alternative job should hang. |
| 13126 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13127 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13128 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13129 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13130 | &hanging_alternate_protocol_socket); |
| 13131 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13132 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13133 | |
| 13134 | HttpRequestInfo request; |
| 13135 | request.method = "GET"; |
| 13136 | request.url = GURL("https://www.example.org/"); |
| 13137 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13138 | request.traffic_annotation = |
| 13139 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13140 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13141 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13142 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13143 | |
| 13144 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13145 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13146 | spdy::SpdySerializedFrame resp( |
| 13147 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13148 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13149 | MockRead spdy_reads[] = { |
| 13150 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13151 | }; |
| 13152 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13153 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13154 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13155 | |
| 13156 | TestCompletionCallback callback; |
| 13157 | |
| 13158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13159 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13160 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13161 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13162 | |
| 13163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13164 | ASSERT_TRUE(response); |
| 13165 | ASSERT_TRUE(response->headers); |
| 13166 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13167 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13168 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13169 | |
| 13170 | std::string response_data; |
| 13171 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13172 | EXPECT_EQ("hello!", response_data); |
| 13173 | |
| 13174 | // Origin host bypasses proxy, no resolution should have happened. |
| 13175 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13176 | } |
| 13177 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13178 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13179 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13180 | proxy_config.set_auto_detect(true); |
| 13181 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13182 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13183 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13184 | session_deps_.proxy_resolution_service = |
| 13185 | std::make_unique<ProxyResolutionService>( |
| 13186 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13187 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13188 | std::make_unique<CapturingProxyResolverFactory>( |
| 13189 | &capturing_proxy_resolver), |
| 13190 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13191 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13192 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13193 | |
| 13194 | HttpRequestInfo request; |
| 13195 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13196 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13197 | request.traffic_annotation = |
| 13198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13199 | |
| 13200 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13201 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13202 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13203 | MockRead("\r\n"), |
| 13204 | MockRead("hello world"), |
| 13205 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13206 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13207 | }; |
| 13208 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13209 | StaticSocketDataProvider first_transaction(data_reads, |
| 13210 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13211 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13212 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13213 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13215 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13216 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13217 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13218 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13219 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13220 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13221 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13222 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13223 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13224 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13225 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13226 | }; |
| 13227 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13228 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13229 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13230 | spdy::SpdySerializedFrame resp( |
| 13231 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13232 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13233 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13234 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13235 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13236 | }; |
| 13237 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13238 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13239 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13240 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13241 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13242 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13243 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13244 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13245 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13246 | &hanging_non_alternate_protocol_socket); |
| 13247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13248 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13249 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13251 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13252 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13254 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13256 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13257 | |
| 13258 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13259 | ASSERT_TRUE(response); |
| 13260 | ASSERT_TRUE(response->headers); |
| 13261 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13262 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13263 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13264 | |
| 13265 | std::string response_data; |
| 13266 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13267 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13268 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13269 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13270 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13271 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13272 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13274 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13275 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13276 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13277 | ASSERT_TRUE(response); |
| 13278 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13279 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13280 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13281 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13282 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13283 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13284 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13285 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13286 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13287 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13288 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13289 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13290 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13291 | LoadTimingInfo load_timing_info; |
| 13292 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13293 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13294 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13295 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13296 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13297 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13298 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13299 | HttpRequestInfo request; |
| 13300 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13301 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13302 | request.traffic_annotation = |
| 13303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13304 | |
| 13305 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13306 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13307 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13308 | MockRead("\r\n"), |
| 13309 | MockRead("hello world"), |
| 13310 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13311 | }; |
| 13312 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13313 | StaticSocketDataProvider first_transaction(data_reads, |
| 13314 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13315 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13316 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13317 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13319 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13320 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13321 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13322 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13323 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13324 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13325 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13326 | spdy::SpdySerializedFrame resp( |
| 13327 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13328 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13329 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13330 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13331 | }; |
| 13332 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13333 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13334 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13335 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13336 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13339 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13340 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13341 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13342 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13343 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13344 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13345 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13346 | |
| 13347 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13348 | ASSERT_TRUE(response); |
| 13349 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13350 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13351 | |
| 13352 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13353 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13354 | EXPECT_EQ("hello world", response_data); |
| 13355 | |
| 13356 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13357 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13358 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13359 | PRIVACY_MODE_DISABLED, |
| 13360 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13361 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13362 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13363 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13364 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13365 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13367 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13369 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13370 | |
| 13371 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13372 | ASSERT_TRUE(response); |
| 13373 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13374 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13375 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13376 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13377 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13378 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13379 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13380 | } |
| 13381 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13382 | // GenerateAuthToken is a mighty big test. |
| 13383 | // It tests all permutation of GenerateAuthToken behavior: |
| 13384 | // - Synchronous and Asynchronous completion. |
| 13385 | // - OK or error on completion. |
| 13386 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13387 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13388 | // - Non-authenticating and authenticating backend. |
| 13389 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13390 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13391 | // problems generating an auth token for an authenticating proxy, we don't |
| 13392 | // need to test all permutations of the backend server). |
| 13393 | // |
| 13394 | // The test proceeds by going over each of the configuration cases, and |
| 13395 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13396 | // specifies both the configuration for the test as well as the expectations |
| 13397 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13398 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13399 | static const char kServer[] = "http://www.example.com"; |
| 13400 | static const char kSecureServer[] = "https://www.example.com"; |
| 13401 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13402 | |
| 13403 | enum AuthTiming { |
| 13404 | AUTH_NONE, |
| 13405 | AUTH_SYNC, |
| 13406 | AUTH_ASYNC, |
| 13407 | }; |
| 13408 | |
| 13409 | const MockWrite kGet( |
| 13410 | "GET / HTTP/1.1\r\n" |
| 13411 | "Host: www.example.com\r\n" |
| 13412 | "Connection: keep-alive\r\n\r\n"); |
| 13413 | const MockWrite kGetProxy( |
| 13414 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13415 | "Host: www.example.com\r\n" |
| 13416 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13417 | const MockWrite kGetAuth( |
| 13418 | "GET / HTTP/1.1\r\n" |
| 13419 | "Host: www.example.com\r\n" |
| 13420 | "Connection: keep-alive\r\n" |
| 13421 | "Authorization: auth_token\r\n\r\n"); |
| 13422 | const MockWrite kGetProxyAuth( |
| 13423 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13424 | "Host: www.example.com\r\n" |
| 13425 | "Proxy-Connection: keep-alive\r\n" |
| 13426 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13427 | const MockWrite kGetAuthThroughProxy( |
| 13428 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13429 | "Host: www.example.com\r\n" |
| 13430 | "Proxy-Connection: keep-alive\r\n" |
| 13431 | "Authorization: auth_token\r\n\r\n"); |
| 13432 | const MockWrite kGetAuthWithProxyAuth( |
| 13433 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13434 | "Host: www.example.com\r\n" |
| 13435 | "Proxy-Connection: keep-alive\r\n" |
| 13436 | "Proxy-Authorization: auth_token\r\n" |
| 13437 | "Authorization: auth_token\r\n\r\n"); |
| 13438 | const MockWrite kConnect( |
| 13439 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13440 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13441 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13442 | const MockWrite kConnectProxyAuth( |
| 13443 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13444 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13445 | "Proxy-Connection: keep-alive\r\n" |
| 13446 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13447 | |
| 13448 | const MockRead kSuccess( |
| 13449 | "HTTP/1.1 200 OK\r\n" |
| 13450 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13451 | "Content-Length: 3\r\n\r\n" |
| 13452 | "Yes"); |
| 13453 | const MockRead kFailure( |
| 13454 | "Should not be called."); |
| 13455 | const MockRead kServerChallenge( |
| 13456 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13457 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13458 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13459 | "Content-Length: 14\r\n\r\n" |
| 13460 | "Unauthorized\r\n"); |
| 13461 | const MockRead kProxyChallenge( |
| 13462 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13463 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13464 | "Proxy-Connection: close\r\n" |
| 13465 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13466 | "Content-Length: 14\r\n\r\n" |
| 13467 | "Unauthorized\r\n"); |
| 13468 | const MockRead kProxyConnected( |
| 13469 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13470 | |
| 13471 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13472 | // no constructors, but the C++ compiler on Windows warns about |
| 13473 | // unspecified data in compound literals. So, moved to using constructors, |
| 13474 | // and TestRound's created with the default constructor should not be used. |
| 13475 | struct TestRound { |
| 13476 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13477 | : expected_rv(ERR_UNEXPECTED), |
| 13478 | extra_write(nullptr), |
| 13479 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13480 | TestRound(const MockWrite& write_arg, |
| 13481 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13482 | int expected_rv_arg) |
| 13483 | : write(write_arg), |
| 13484 | read(read_arg), |
| 13485 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 13486 | extra_write(nullptr), |
| 13487 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13488 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13489 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13490 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13491 | : write(write_arg), |
| 13492 | read(read_arg), |
| 13493 | expected_rv(expected_rv_arg), |
| 13494 | extra_write(extra_write_arg), |
| 13495 | extra_read(extra_read_arg) { |
| 13496 | } |
| 13497 | MockWrite write; |
| 13498 | MockRead read; |
| 13499 | int expected_rv; |
| 13500 | const MockWrite* extra_write; |
| 13501 | const MockRead* extra_read; |
| 13502 | }; |
| 13503 | |
| 13504 | static const int kNoSSL = 500; |
| 13505 | |
| 13506 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13507 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13508 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13509 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13510 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13511 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13512 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13513 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13514 | int num_auth_rounds; |
| 13515 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13516 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13517 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13518 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13519 | {__LINE__, |
| 13520 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13521 | AUTH_NONE, |
| 13522 | OK, |
| 13523 | kServer, |
| 13524 | AUTH_NONE, |
| 13525 | OK, |
| 13526 | 1, |
| 13527 | kNoSSL, |
| 13528 | {TestRound(kGet, kSuccess, OK)}}, |
| 13529 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13530 | {__LINE__, |
| 13531 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13532 | AUTH_NONE, |
| 13533 | OK, |
| 13534 | kServer, |
| 13535 | AUTH_SYNC, |
| 13536 | OK, |
| 13537 | 2, |
| 13538 | kNoSSL, |
| 13539 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13540 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13541 | {__LINE__, |
| 13542 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13543 | AUTH_NONE, |
| 13544 | OK, |
| 13545 | kServer, |
| 13546 | AUTH_SYNC, |
| 13547 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13548 | 3, |
| 13549 | kNoSSL, |
| 13550 | {TestRound(kGet, kServerChallenge, OK), |
| 13551 | TestRound(kGet, kServerChallenge, OK), |
| 13552 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13553 | {__LINE__, |
| 13554 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13555 | AUTH_NONE, |
| 13556 | OK, |
| 13557 | kServer, |
| 13558 | AUTH_SYNC, |
| 13559 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13560 | 2, |
| 13561 | kNoSSL, |
| 13562 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13563 | {__LINE__, |
| 13564 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13565 | AUTH_NONE, |
| 13566 | OK, |
| 13567 | kServer, |
| 13568 | AUTH_SYNC, |
| 13569 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13570 | 2, |
| 13571 | kNoSSL, |
| 13572 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13573 | {__LINE__, |
| 13574 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13575 | AUTH_SYNC, |
| 13576 | ERR_FAILED, |
| 13577 | kServer, |
| 13578 | AUTH_NONE, |
| 13579 | OK, |
| 13580 | 2, |
| 13581 | kNoSSL, |
| 13582 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13583 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13584 | {__LINE__, |
| 13585 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13586 | AUTH_ASYNC, |
| 13587 | ERR_FAILED, |
| 13588 | kServer, |
| 13589 | AUTH_NONE, |
| 13590 | OK, |
| 13591 | 2, |
| 13592 | kNoSSL, |
| 13593 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13594 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13595 | {__LINE__, |
| 13596 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13597 | AUTH_NONE, |
| 13598 | OK, |
| 13599 | kServer, |
| 13600 | AUTH_SYNC, |
| 13601 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13602 | 2, |
| 13603 | kNoSSL, |
| 13604 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13605 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13606 | {__LINE__, |
| 13607 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13608 | AUTH_NONE, |
| 13609 | OK, |
| 13610 | kServer, |
| 13611 | AUTH_ASYNC, |
| 13612 | ERR_FAILED, |
| 13613 | 2, |
| 13614 | kNoSSL, |
| 13615 | {TestRound(kGet, kServerChallenge, OK), |
| 13616 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13617 | {__LINE__, |
| 13618 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13619 | AUTH_NONE, |
| 13620 | OK, |
| 13621 | kServer, |
| 13622 | AUTH_ASYNC, |
| 13623 | OK, |
| 13624 | 2, |
| 13625 | kNoSSL, |
| 13626 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13627 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13628 | {__LINE__, |
| 13629 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13630 | AUTH_NONE, |
| 13631 | OK, |
| 13632 | kServer, |
| 13633 | AUTH_ASYNC, |
| 13634 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13635 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13636 | kNoSSL, |
| 13637 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13638 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13639 | TestRound(kGet, kServerChallenge, OK), |
| 13640 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13641 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13642 | {__LINE__, |
| 13643 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13644 | AUTH_NONE, |
| 13645 | OK, |
| 13646 | kServer, |
| 13647 | AUTH_NONE, |
| 13648 | OK, |
| 13649 | 1, |
| 13650 | kNoSSL, |
| 13651 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13652 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13653 | {__LINE__, |
| 13654 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13655 | AUTH_NONE, |
| 13656 | OK, |
| 13657 | kServer, |
| 13658 | AUTH_SYNC, |
| 13659 | OK, |
| 13660 | 2, |
| 13661 | kNoSSL, |
| 13662 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13663 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13664 | {__LINE__, |
| 13665 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13666 | AUTH_NONE, |
| 13667 | OK, |
| 13668 | kServer, |
| 13669 | AUTH_SYNC, |
| 13670 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13671 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13672 | kNoSSL, |
| 13673 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13674 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13675 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13676 | {__LINE__, |
| 13677 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13678 | AUTH_NONE, |
| 13679 | OK, |
| 13680 | kServer, |
| 13681 | AUTH_ASYNC, |
| 13682 | OK, |
| 13683 | 2, |
| 13684 | kNoSSL, |
| 13685 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13686 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13687 | {__LINE__, |
| 13688 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13689 | AUTH_NONE, |
| 13690 | OK, |
| 13691 | kServer, |
| 13692 | AUTH_ASYNC, |
| 13693 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13694 | 2, |
| 13695 | kNoSSL, |
| 13696 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13697 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13698 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13699 | {__LINE__, |
| 13700 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13701 | AUTH_SYNC, |
| 13702 | OK, |
| 13703 | kServer, |
| 13704 | AUTH_NONE, |
| 13705 | OK, |
| 13706 | 2, |
| 13707 | kNoSSL, |
| 13708 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13709 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13710 | {__LINE__, |
| 13711 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13712 | AUTH_SYNC, |
| 13713 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13714 | kServer, |
| 13715 | AUTH_NONE, |
| 13716 | OK, |
| 13717 | 2, |
| 13718 | kNoSSL, |
| 13719 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13720 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13721 | {__LINE__, |
| 13722 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13723 | AUTH_ASYNC, |
| 13724 | OK, |
| 13725 | kServer, |
| 13726 | AUTH_NONE, |
| 13727 | OK, |
| 13728 | 2, |
| 13729 | kNoSSL, |
| 13730 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13731 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13732 | {__LINE__, |
| 13733 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13734 | AUTH_ASYNC, |
| 13735 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13736 | kServer, |
| 13737 | AUTH_NONE, |
| 13738 | OK, |
| 13739 | 2, |
| 13740 | kNoSSL, |
| 13741 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13742 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13743 | {__LINE__, |
| 13744 | kProxy, |
| 13745 | AUTH_ASYNC, |
| 13746 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13747 | kServer, |
| 13748 | AUTH_NONE, |
| 13749 | OK, |
| 13750 | 3, |
| 13751 | kNoSSL, |
| 13752 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13753 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13754 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13755 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13756 | {__LINE__, |
| 13757 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13758 | AUTH_SYNC, |
| 13759 | OK, |
| 13760 | kServer, |
| 13761 | AUTH_SYNC, |
| 13762 | OK, |
| 13763 | 3, |
| 13764 | kNoSSL, |
| 13765 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13766 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13767 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13768 | {__LINE__, |
| 13769 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13770 | AUTH_SYNC, |
| 13771 | OK, |
| 13772 | kServer, |
| 13773 | AUTH_SYNC, |
| 13774 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13775 | 3, |
| 13776 | kNoSSL, |
| 13777 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13778 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13779 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13780 | {__LINE__, |
| 13781 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13782 | AUTH_ASYNC, |
| 13783 | OK, |
| 13784 | kServer, |
| 13785 | AUTH_SYNC, |
| 13786 | OK, |
| 13787 | 3, |
| 13788 | kNoSSL, |
| 13789 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13790 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13791 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13792 | {__LINE__, |
| 13793 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13794 | AUTH_ASYNC, |
| 13795 | OK, |
| 13796 | kServer, |
| 13797 | AUTH_SYNC, |
| 13798 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13799 | 3, |
| 13800 | kNoSSL, |
| 13801 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13802 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13803 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13804 | {__LINE__, |
| 13805 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13806 | AUTH_SYNC, |
| 13807 | OK, |
| 13808 | kServer, |
| 13809 | AUTH_ASYNC, |
| 13810 | OK, |
| 13811 | 3, |
| 13812 | kNoSSL, |
| 13813 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13814 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13815 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13816 | {__LINE__, |
| 13817 | kProxy, |
| 13818 | AUTH_SYNC, |
| 13819 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13820 | kServer, |
| 13821 | AUTH_ASYNC, |
| 13822 | OK, |
| 13823 | 4, |
| 13824 | kNoSSL, |
| 13825 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13826 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13827 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13828 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13829 | {__LINE__, |
| 13830 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13831 | AUTH_SYNC, |
| 13832 | OK, |
| 13833 | kServer, |
| 13834 | AUTH_ASYNC, |
| 13835 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13836 | 3, |
| 13837 | kNoSSL, |
| 13838 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13839 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13840 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13841 | {__LINE__, |
| 13842 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13843 | AUTH_ASYNC, |
| 13844 | OK, |
| 13845 | kServer, |
| 13846 | AUTH_ASYNC, |
| 13847 | OK, |
| 13848 | 3, |
| 13849 | kNoSSL, |
| 13850 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13851 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13852 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13853 | {__LINE__, |
| 13854 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13855 | AUTH_ASYNC, |
| 13856 | OK, |
| 13857 | kServer, |
| 13858 | AUTH_ASYNC, |
| 13859 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13860 | 3, |
| 13861 | kNoSSL, |
| 13862 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13863 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13864 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13865 | {__LINE__, |
| 13866 | kProxy, |
| 13867 | AUTH_ASYNC, |
| 13868 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13869 | kServer, |
| 13870 | AUTH_ASYNC, |
| 13871 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13872 | 4, |
| 13873 | kNoSSL, |
| 13874 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13875 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13876 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13877 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13878 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13879 | {__LINE__, |
| 13880 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13881 | AUTH_NONE, |
| 13882 | OK, |
| 13883 | kSecureServer, |
| 13884 | AUTH_NONE, |
| 13885 | OK, |
| 13886 | 1, |
| 13887 | 0, |
| 13888 | {TestRound(kGet, kSuccess, OK)}}, |
| 13889 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13890 | {__LINE__, |
| 13891 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13892 | AUTH_NONE, |
| 13893 | OK, |
| 13894 | kSecureServer, |
| 13895 | AUTH_SYNC, |
| 13896 | OK, |
| 13897 | 2, |
| 13898 | 0, |
| 13899 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13900 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13901 | {__LINE__, |
| 13902 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13903 | AUTH_NONE, |
| 13904 | OK, |
| 13905 | kSecureServer, |
| 13906 | AUTH_SYNC, |
| 13907 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13908 | 2, |
| 13909 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13910 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13911 | {__LINE__, |
| 13912 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13913 | AUTH_NONE, |
| 13914 | OK, |
| 13915 | kSecureServer, |
| 13916 | AUTH_ASYNC, |
| 13917 | OK, |
| 13918 | 2, |
| 13919 | 0, |
| 13920 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13921 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13922 | {__LINE__, |
| 13923 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13924 | AUTH_NONE, |
| 13925 | OK, |
| 13926 | kSecureServer, |
| 13927 | AUTH_ASYNC, |
| 13928 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13929 | 2, |
| 13930 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13931 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13932 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13933 | {__LINE__, |
| 13934 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13935 | AUTH_NONE, |
| 13936 | OK, |
| 13937 | kSecureServer, |
| 13938 | AUTH_NONE, |
| 13939 | OK, |
| 13940 | 1, |
| 13941 | 0, |
| 13942 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13943 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13944 | {__LINE__, |
| 13945 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13946 | AUTH_NONE, |
| 13947 | OK, |
| 13948 | kSecureServer, |
| 13949 | AUTH_SYNC, |
| 13950 | OK, |
| 13951 | 2, |
| 13952 | 0, |
| 13953 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13954 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13955 | {__LINE__, |
| 13956 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13957 | AUTH_NONE, |
| 13958 | OK, |
| 13959 | kSecureServer, |
| 13960 | AUTH_SYNC, |
| 13961 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13962 | 2, |
| 13963 | 0, |
| 13964 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13965 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13966 | {__LINE__, |
| 13967 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13968 | AUTH_NONE, |
| 13969 | OK, |
| 13970 | kSecureServer, |
| 13971 | AUTH_ASYNC, |
| 13972 | OK, |
| 13973 | 2, |
| 13974 | 0, |
| 13975 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13976 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13977 | {__LINE__, |
| 13978 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13979 | AUTH_NONE, |
| 13980 | OK, |
| 13981 | kSecureServer, |
| 13982 | AUTH_ASYNC, |
| 13983 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13984 | 2, |
| 13985 | 0, |
| 13986 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13987 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13988 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13989 | {__LINE__, |
| 13990 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13991 | AUTH_SYNC, |
| 13992 | OK, |
| 13993 | kSecureServer, |
| 13994 | AUTH_NONE, |
| 13995 | OK, |
| 13996 | 2, |
| 13997 | 1, |
| 13998 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13999 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14000 | {__LINE__, |
| 14001 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14002 | AUTH_SYNC, |
| 14003 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14004 | kSecureServer, |
| 14005 | AUTH_NONE, |
| 14006 | OK, |
| 14007 | 2, |
| 14008 | kNoSSL, |
| 14009 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14010 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14011 | {__LINE__, |
| 14012 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14013 | AUTH_SYNC, |
| 14014 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14015 | kSecureServer, |
| 14016 | AUTH_NONE, |
| 14017 | OK, |
| 14018 | 2, |
| 14019 | kNoSSL, |
| 14020 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14021 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14022 | {__LINE__, |
| 14023 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14024 | AUTH_SYNC, |
| 14025 | ERR_UNEXPECTED, |
| 14026 | kSecureServer, |
| 14027 | AUTH_NONE, |
| 14028 | OK, |
| 14029 | 2, |
| 14030 | kNoSSL, |
| 14031 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14032 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14033 | {__LINE__, |
| 14034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14035 | AUTH_ASYNC, |
| 14036 | OK, |
| 14037 | kSecureServer, |
| 14038 | AUTH_NONE, |
| 14039 | OK, |
| 14040 | 2, |
| 14041 | 1, |
| 14042 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14043 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14044 | {__LINE__, |
| 14045 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14046 | AUTH_ASYNC, |
| 14047 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14048 | kSecureServer, |
| 14049 | AUTH_NONE, |
| 14050 | OK, |
| 14051 | 2, |
| 14052 | kNoSSL, |
| 14053 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14054 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14055 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14056 | {__LINE__, |
| 14057 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14058 | AUTH_SYNC, |
| 14059 | OK, |
| 14060 | kSecureServer, |
| 14061 | AUTH_SYNC, |
| 14062 | OK, |
| 14063 | 3, |
| 14064 | 1, |
| 14065 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14066 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14067 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14068 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14069 | {__LINE__, |
| 14070 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14071 | AUTH_SYNC, |
| 14072 | OK, |
| 14073 | kSecureServer, |
| 14074 | AUTH_SYNC, |
| 14075 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14076 | 3, |
| 14077 | 1, |
| 14078 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14079 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14080 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14081 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14082 | {__LINE__, |
| 14083 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14084 | AUTH_ASYNC, |
| 14085 | OK, |
| 14086 | kSecureServer, |
| 14087 | AUTH_SYNC, |
| 14088 | OK, |
| 14089 | 3, |
| 14090 | 1, |
| 14091 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14092 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14093 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14094 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14095 | {__LINE__, |
| 14096 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14097 | AUTH_ASYNC, |
| 14098 | OK, |
| 14099 | kSecureServer, |
| 14100 | AUTH_SYNC, |
| 14101 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14102 | 3, |
| 14103 | 1, |
| 14104 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14105 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14106 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14107 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14108 | {__LINE__, |
| 14109 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14110 | AUTH_SYNC, |
| 14111 | OK, |
| 14112 | kSecureServer, |
| 14113 | AUTH_ASYNC, |
| 14114 | OK, |
| 14115 | 3, |
| 14116 | 1, |
| 14117 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14118 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14119 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14120 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14121 | {__LINE__, |
| 14122 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14123 | AUTH_SYNC, |
| 14124 | OK, |
| 14125 | kSecureServer, |
| 14126 | AUTH_ASYNC, |
| 14127 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14128 | 3, |
| 14129 | 1, |
| 14130 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14131 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14132 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14133 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14134 | {__LINE__, |
| 14135 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14136 | AUTH_ASYNC, |
| 14137 | OK, |
| 14138 | kSecureServer, |
| 14139 | AUTH_ASYNC, |
| 14140 | OK, |
| 14141 | 3, |
| 14142 | 1, |
| 14143 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14144 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14145 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14146 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14147 | {__LINE__, |
| 14148 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14149 | AUTH_ASYNC, |
| 14150 | OK, |
| 14151 | kSecureServer, |
| 14152 | AUTH_ASYNC, |
| 14153 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14154 | 3, |
| 14155 | 1, |
| 14156 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14157 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14158 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14159 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14160 | {__LINE__, |
| 14161 | kProxy, |
| 14162 | AUTH_ASYNC, |
| 14163 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14164 | kSecureServer, |
| 14165 | AUTH_ASYNC, |
| 14166 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14167 | 4, |
| 14168 | 2, |
| 14169 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14170 | TestRound(kConnect, kProxyChallenge, OK), |
| 14171 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14172 | &kServerChallenge), |
| 14173 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14174 | }; |
| 14175 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14176 | for (const auto& test_config : test_configs) { |
| 14177 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14178 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14179 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14180 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14181 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14182 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14183 | |
| 14184 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14185 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14186 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14187 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14188 | std::string auth_challenge = "Mock realm=proxy"; |
| 14189 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14190 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14191 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14192 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14193 | empty_ssl_info, origin, |
| 14194 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14195 | auth_handler->SetGenerateExpectation( |
| 14196 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14197 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14198 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14199 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14200 | } |
| 14201 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14202 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14203 | std::string auth_challenge = "Mock realm=server"; |
| 14204 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14205 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14206 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14207 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14208 | empty_ssl_info, origin, |
| 14209 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14210 | auth_handler->SetGenerateExpectation( |
| 14211 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14212 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14213 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14214 | |
| 14215 | // The second handler always succeeds. It should only be used where there |
| 14216 | // are multiple auth sessions for server auth in the same network |
| 14217 | // transaction using the same auth scheme. |
| 14218 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14219 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14220 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14221 | empty_ssl_info, origin, |
| 14222 | NetLogWithSource()); |
| 14223 | second_handler->SetGenerateExpectation(true, OK); |
| 14224 | auth_factory->AddMockHandler(second_handler.release(), |
| 14225 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14226 | } |
| 14227 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14228 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14229 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14230 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14231 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14232 | session_deps_.proxy_resolution_service = |
| 14233 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14234 | } |
| 14235 | |
| 14236 | HttpRequestInfo request; |
| 14237 | request.method = "GET"; |
| 14238 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14239 | request.traffic_annotation = |
| 14240 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14241 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14243 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14244 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14245 | |
| 14246 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14247 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14248 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14249 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14250 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14251 | |
| 14252 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14253 | mock_reads.back().push_back(read_write_round.read); |
| 14254 | mock_writes.back().push_back(read_write_round.write); |
| 14255 | |
| 14256 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14257 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14258 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14259 | mock_reads.push_back(std::vector<MockRead>()); |
| 14260 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14261 | } |
| 14262 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14263 | if (read_write_round.extra_read) { |
| 14264 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14265 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14266 | if (read_write_round.extra_write) { |
| 14267 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14268 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14269 | |
| 14270 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14271 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14272 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14273 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14274 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14276 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14277 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14278 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14279 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14280 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14281 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14282 | } |
| 14283 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14284 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14285 | // they are as well. |
| 14286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14287 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14288 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14289 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14290 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14291 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14292 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14293 | int rv; |
| 14294 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14295 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14296 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14297 | rv = trans.RestartWithAuth( |
| 14298 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14299 | } |
| 14300 | if (rv == ERR_IO_PENDING) |
| 14301 | rv = callback.WaitForResult(); |
| 14302 | |
| 14303 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14304 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14305 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14306 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14307 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14308 | continue; |
| 14309 | } |
| 14310 | if (round + 1 < test_config.num_auth_rounds) { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14311 | EXPECT_TRUE(response->auth_challenge.has_value()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14312 | } else { |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14313 | EXPECT_FALSE(response->auth_challenge.has_value()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14314 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14315 | } |
| 14316 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14317 | } |
| 14318 | } |
| 14319 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14320 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14321 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14322 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14323 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14324 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14325 | session_deps_.proxy_resolution_service = |
| 14326 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14327 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14328 | |
| 14329 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14330 | auth_handler->set_connection_based(true); |
| 14331 | std::string auth_challenge = "Mock realm=server"; |
| 14332 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14333 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14334 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14335 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14336 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14337 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14338 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14339 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14340 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 14341 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14342 | HttpRequestInfo request; |
| 14343 | request.method = "GET"; |
| 14344 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14345 | request.traffic_annotation = |
| 14346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14347 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14349 | |
| 14350 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14351 | // to validate that the TCP socket is not released to the pool between |
| 14352 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14353 | HttpNetworkSessionPeer session_peer(session.get()); |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14354 | CommonConnectJobParams common_connect_job_params( |
| 14355 | session->CreateCommonConnectJobParams()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14356 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14357 | 50, // Max sockets for pool |
| 14358 | 1, // Max sockets per group |
| 14359 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | aafff54 | 2019-04-22 22:09:36 | [diff] [blame^] | 14360 | ProxyServer::Direct(), false, // is_for_websockets |
Matt Menke | d6fd2a5 | 2019-03-20 06:14:36 | [diff] [blame] | 14361 | &common_connect_job_params, session_deps_.ssl_config_service.get()); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14362 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14363 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14364 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14365 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14367 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14368 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14369 | |
| 14370 | const MockWrite kGet( |
| 14371 | "GET / HTTP/1.1\r\n" |
| 14372 | "Host: www.example.com\r\n" |
| 14373 | "Connection: keep-alive\r\n\r\n"); |
| 14374 | const MockWrite kGetAuth( |
| 14375 | "GET / HTTP/1.1\r\n" |
| 14376 | "Host: www.example.com\r\n" |
| 14377 | "Connection: keep-alive\r\n" |
| 14378 | "Authorization: auth_token\r\n\r\n"); |
| 14379 | |
| 14380 | const MockRead kServerChallenge( |
| 14381 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14382 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14383 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14384 | "Content-Length: 14\r\n\r\n" |
| 14385 | "Unauthorized\r\n"); |
| 14386 | const MockRead kSuccess( |
| 14387 | "HTTP/1.1 200 OK\r\n" |
| 14388 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14389 | "Content-Length: 3\r\n\r\n" |
| 14390 | "Yes"); |
| 14391 | |
| 14392 | MockWrite writes[] = { |
| 14393 | // First round |
| 14394 | kGet, |
| 14395 | // Second round |
| 14396 | kGetAuth, |
| 14397 | // Third round |
| 14398 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14399 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14400 | kGetAuth, |
| 14401 | // Competing request |
| 14402 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14403 | }; |
| 14404 | MockRead reads[] = { |
| 14405 | // First round |
| 14406 | kServerChallenge, |
| 14407 | // Second round |
| 14408 | kServerChallenge, |
| 14409 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14410 | kServerChallenge, |
| 14411 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14412 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14413 | // Competing response |
| 14414 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14415 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14416 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14417 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14418 | |
Matt Menke | f6edce75 | 2019-03-19 17:21:56 | [diff] [blame] | 14419 | const ClientSocketPool::GroupId kSocketGroup( |
| 14420 | HostPortPair("www.example.com", 80), ClientSocketPool::SocketType::kHttp, |
Matt Menke | bdf77780 | 2019-04-22 19:38:59 | [diff] [blame] | 14421 | PrivacyMode::PRIVACY_MODE_DISABLED); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14422 | |
| 14423 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14424 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14425 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14426 | if (rv == ERR_IO_PENDING) |
| 14427 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14428 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14429 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14430 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14431 | EXPECT_TRUE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14432 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14433 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14434 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14435 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14436 | // In between rounds, another request comes in for the same domain. |
| 14437 | // It should not be able to grab the TCP socket that trans has already |
| 14438 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14439 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14440 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14441 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14442 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14444 | // callback_compete.WaitForResult at this point would stall forever, |
| 14445 | // since the HttpNetworkTransaction does not release the request back to |
| 14446 | // the pool until after authentication completes. |
| 14447 | |
| 14448 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14449 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14450 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14451 | if (rv == ERR_IO_PENDING) |
| 14452 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14453 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14454 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14455 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14456 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14457 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14458 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14459 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14460 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14461 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14462 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14463 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14464 | if (rv == ERR_IO_PENDING) |
| 14465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14466 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14467 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14468 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14469 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14470 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14471 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14472 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14473 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14474 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14475 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14476 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14477 | if (rv == ERR_IO_PENDING) |
| 14478 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14479 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14480 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14481 | ASSERT_TRUE(response); |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 14482 | EXPECT_FALSE(response->auth_challenge.has_value()); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14483 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14484 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14485 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14486 | // auth handler should transition to a DONE state in concert with the remote |
| 14487 | // server. But that's not something we can test here with a mock handler. |
| 14488 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14489 | auth_handler->state()); |
| 14490 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14491 | // Read the body since the fourth round was successful. This will also |
| 14492 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14493 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14494 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14495 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14496 | if (rv == ERR_IO_PENDING) |
| 14497 | rv = callback.WaitForResult(); |
| 14498 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14499 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14500 | EXPECT_EQ(0, rv); |
| 14501 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14502 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14503 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14504 | |
| 14505 | // The competing request can now finish. Wait for the headers and then |
| 14506 | // read the body. |
| 14507 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14508 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14509 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14510 | if (rv == ERR_IO_PENDING) |
| 14511 | rv = callback.WaitForResult(); |
| 14512 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14513 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14514 | EXPECT_EQ(0, rv); |
| 14515 | |
| 14516 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14517 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14518 | } |
| 14519 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14520 | // This tests the case that a request is issued via http instead of spdy after |
| 14521 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14522 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14523 | HttpRequestInfo request; |
| 14524 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14525 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14526 | request.traffic_annotation = |
| 14527 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14528 | |
| 14529 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14530 | MockWrite( |
| 14531 | "GET / HTTP/1.1\r\n" |
| 14532 | "Host: www.example.org\r\n" |
| 14533 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14534 | }; |
| 14535 | |
| 14536 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14537 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14538 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14539 | MockRead("\r\n"), |
| 14540 | MockRead("hello world"), |
| 14541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14542 | }; |
| 14543 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14544 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14545 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14546 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14547 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14548 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14549 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14550 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14552 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14553 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14556 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14557 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14558 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14560 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14563 | ASSERT_TRUE(response); |
| 14564 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14565 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14566 | |
| 14567 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14568 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14569 | EXPECT_EQ("hello world", response_data); |
| 14570 | |
| 14571 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14572 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14573 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14574 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14575 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14576 | // immediate server closing of the socket. |
| 14577 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14578 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14579 | HttpRequestInfo request; |
| 14580 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14581 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14582 | request.traffic_annotation = |
| 14583 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14584 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14585 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14586 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14588 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14589 | spdy::SpdySerializedFrame req( |
| 14590 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14591 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14592 | |
| 14593 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14594 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14595 | }; |
| 14596 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14597 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14598 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14600 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14604 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14605 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14606 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14607 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14608 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14609 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14610 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14611 | // it gets it. This is needed since the auth handler may get destroyed |
| 14612 | // before we get a chance to query it. |
| 14613 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14614 | public: |
| 14615 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14616 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14617 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14618 | |
| 14619 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14620 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14621 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14622 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14623 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14624 | *url_ = request->url; |
| 14625 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14626 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14627 | } |
| 14628 | |
| 14629 | private: |
| 14630 | GURL* url_; |
| 14631 | }; |
| 14632 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14633 | // Test that if we cancel the transaction as the connection is completing, that |
| 14634 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14635 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14636 | // Setup everything about the connection to complete synchronously, so that |
| 14637 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14638 | // for is the callback from the HttpStreamRequest. |
| 14639 | // Then cancel the transaction. |
| 14640 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14641 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14642 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14643 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14644 | MockRead(SYNCHRONOUS, "hello world"), |
| 14645 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14646 | }; |
| 14647 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14648 | HttpRequestInfo request; |
| 14649 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14650 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14651 | request.traffic_annotation = |
| 14652 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14655 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14656 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14657 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14658 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14659 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14661 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14662 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14663 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14664 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14665 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14667 | trans.reset(); // Cancel the transaction here. |
| 14668 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14669 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14670 | } |
| 14671 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14672 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14673 | // stream is drained properly and added back to the socket pool. The main |
| 14674 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14675 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14676 | // deleted. |
| 14677 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14678 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14679 | MockRead data_reads[] = { |
| 14680 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14681 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14682 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14683 | MockRead(ASYNC, "1"), |
| 14684 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14685 | // HttpNetworkTransaction has been deleted. |
| 14686 | MockRead(ASYNC, "2"), |
| 14687 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14688 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14689 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14693 | |
| 14694 | { |
| 14695 | HttpRequestInfo request; |
| 14696 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14697 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14698 | request.traffic_annotation = |
| 14699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14700 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14701 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14702 | TestCompletionCallback callback; |
| 14703 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14704 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14705 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14706 | callback.WaitForResult(); |
| 14707 | |
| 14708 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14709 | ASSERT_TRUE(response); |
| 14710 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14711 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14712 | |
| 14713 | // The transaction and HttpRequestInfo are deleted. |
| 14714 | } |
| 14715 | |
| 14716 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14717 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14718 | |
| 14719 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14720 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14721 | } |
| 14722 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14723 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14724 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14725 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14726 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14727 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14728 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14729 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14730 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14731 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14732 | HttpRequestInfo request; |
| 14733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14734 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14735 | request.traffic_annotation = |
| 14736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14737 | |
| 14738 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14739 | MockWrite( |
| 14740 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14741 | "Host: www.example.org\r\n" |
| 14742 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14743 | }; |
| 14744 | |
| 14745 | MockRead data_reads1[] = { |
| 14746 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14747 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14748 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14749 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14750 | }; |
| 14751 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14752 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14753 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14755 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14758 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14759 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14760 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14761 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14763 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14765 | |
| 14766 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14767 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14769 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14770 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14771 | |
| 14772 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14773 | EXPECT_EQ(200, response->headers->response_code()); |
| 14774 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14775 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14776 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14777 | HostPortPair::FromString("myproxy:70")), |
| 14778 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14779 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14780 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14781 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14782 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14783 | |
| 14784 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14785 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14786 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14787 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14788 | } |
| 14789 | |
| 14790 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14791 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14792 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14793 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14794 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14795 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14796 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14798 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14799 | HttpRequestInfo request; |
| 14800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14801 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14802 | request.traffic_annotation = |
| 14803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14804 | |
| 14805 | // Since we have proxy, should try to establish tunnel. |
| 14806 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14807 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14808 | "Host: www.example.org:443\r\n" |
| 14809 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14810 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14811 | MockWrite("GET / HTTP/1.1\r\n" |
| 14812 | "Host: www.example.org\r\n" |
| 14813 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14814 | }; |
| 14815 | |
| 14816 | MockRead data_reads1[] = { |
| 14817 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14818 | |
| 14819 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14820 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14821 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14822 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14823 | }; |
| 14824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14825 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14826 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14827 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14830 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14833 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14834 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14835 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14836 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14838 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14840 | |
| 14841 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14842 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14843 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14844 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14845 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14846 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14847 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14848 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14849 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14850 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14851 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14853 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14854 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14855 | |
| 14856 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14857 | EXPECT_EQ(200, response->headers->response_code()); |
| 14858 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14859 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14860 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14861 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14862 | HostPortPair::FromString("myproxy:70")), |
| 14863 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14864 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14865 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14866 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14867 | |
| 14868 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14869 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14870 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14871 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14872 | } |
| 14873 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14874 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14875 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14876 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14877 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14878 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14879 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14880 | BoundTestNetLog log; |
| 14881 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14883 | |
| 14884 | HttpRequestInfo request; |
| 14885 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14886 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14887 | request.traffic_annotation = |
| 14888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14889 | |
| 14890 | // Since we have proxy, should try to establish tunnel. |
| 14891 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14892 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14893 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14894 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14895 | |
| 14896 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14897 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14898 | "Connection: keep-alive\r\n\r\n"), |
| 14899 | }; |
| 14900 | |
| 14901 | MockRead data_reads1[] = { |
| 14902 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14903 | |
| 14904 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14905 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14906 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14907 | MockRead(SYNCHRONOUS, OK), |
| 14908 | }; |
| 14909 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14910 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14911 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14912 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14914 | |
| 14915 | TestCompletionCallback callback1; |
| 14916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14917 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14919 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14921 | |
| 14922 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14923 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14924 | TestNetLogEntry::List entries; |
| 14925 | log.GetEntries(&entries); |
| 14926 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14927 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14928 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14929 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14930 | entries, pos, |
| 14931 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14932 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14934 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14935 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14936 | |
| 14937 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14938 | EXPECT_EQ(200, response->headers->response_code()); |
| 14939 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14940 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14941 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14942 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14943 | HostPortPair::FromString("myproxy:70")), |
| 14944 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14945 | |
| 14946 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14947 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14948 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14949 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14950 | } |
| 14951 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14952 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14953 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14954 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14955 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14956 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14957 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14958 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14960 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14961 | HttpRequestInfo request; |
| 14962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14963 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14964 | request.traffic_annotation = |
| 14965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14966 | |
| 14967 | // Since we have proxy, should try to establish tunnel. |
| 14968 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14969 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14970 | "Host: www.example.org:443\r\n" |
| 14971 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14972 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14973 | MockWrite("GET / HTTP/1.1\r\n" |
| 14974 | "Host: www.example.org\r\n" |
| 14975 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14976 | }; |
| 14977 | |
| 14978 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14979 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14980 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14981 | }; |
| 14982 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14983 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14984 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14985 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14988 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14990 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14992 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14994 | |
| 14995 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14996 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14997 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14998 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14999 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15000 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15001 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15002 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15003 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15004 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15005 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15006 | } |
| 15007 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15008 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15009 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15010 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15011 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15012 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15013 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15014 | spdy::SpdySerializedFrame resp( |
| 15015 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15016 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15017 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15018 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15019 | }; |
| 15020 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15021 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15022 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15023 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15024 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15025 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15026 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15029 | |
| 15030 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15031 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15032 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15033 | PRIVACY_MODE_DISABLED, |
| 15034 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15035 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15036 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15037 | |
| 15038 | HttpRequestInfo request; |
| 15039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15040 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15041 | request.traffic_annotation = |
| 15042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15043 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15045 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15046 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15047 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15049 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15050 | } |
| 15051 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15052 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15053 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15054 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15055 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15056 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15057 | request_info.url = GURL("https://www.example.com/"); |
| 15058 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15059 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15060 | request_info.traffic_annotation = |
| 15061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15062 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15063 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15064 | MockWrite data_writes[] = { |
| 15065 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15066 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15067 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15068 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15072 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15074 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15075 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15076 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15077 | rv = callback.WaitForResult(); |
| 15078 | ASSERT_EQ(error, rv); |
| 15079 | } |
| 15080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15081 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15082 | // Just check a grab bag of cert errors. |
| 15083 | static const int kErrors[] = { |
| 15084 | ERR_CERT_COMMON_NAME_INVALID, |
| 15085 | ERR_CERT_AUTHORITY_INVALID, |
| 15086 | ERR_CERT_DATE_INVALID, |
| 15087 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15088 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15089 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15090 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15091 | } |
| 15092 | } |
| 15093 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15094 | // Ensure that a client certificate is removed from the SSL client auth |
| 15095 | // cache when: |
| 15096 | // 1) No proxy is involved. |
| 15097 | // 2) TLS False Start is disabled. |
| 15098 | // 3) The initial TLS handshake requests a client certificate. |
| 15099 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15100 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15101 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15102 | request_info.url = GURL("https://www.example.com/"); |
| 15103 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15104 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15105 | request_info.traffic_annotation = |
| 15106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15107 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15108 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15109 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15110 | |
| 15111 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15112 | // CertificateRequest is received for the first time, the handshake will |
| 15113 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15114 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15115 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15117 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15118 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15119 | |
| 15120 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15121 | // False Start is not being used, the result of the SSL handshake will be |
| 15122 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15123 | // matches the result of a server sending a handshake_failure alert, |
| 15124 | // rather than a Finished message, because it requires a client |
| 15125 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15126 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15127 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15128 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15129 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15130 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15131 | |
| 15132 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15133 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15134 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15135 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15136 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15137 | // requiring a client certificate, this fallback handshake should also |
| 15138 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15139 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15140 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15141 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15143 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15144 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15145 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15146 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15147 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15148 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15149 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15150 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15151 | // requiring a client certificate, this fallback handshake should also |
| 15152 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15153 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15154 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15156 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15157 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15158 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15160 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15161 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15162 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15163 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15164 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15165 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15166 | |
| 15167 | // Complete the SSL handshake, which should abort due to requiring a |
| 15168 | // client certificate. |
| 15169 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15170 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15171 | |
| 15172 | // Indicate that no certificate should be supplied. From the perspective |
| 15173 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15174 | // certificate, so this is the same as supply a |
| 15175 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15176 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15177 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15178 | |
| 15179 | // Ensure the certificate was added to the client auth cache before |
| 15180 | // allowing the connection to continue restarting. |
| 15181 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15182 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15183 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15184 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15185 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15186 | |
| 15187 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15188 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15189 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15190 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15191 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15192 | |
| 15193 | // Ensure that the client certificate is removed from the cache on a |
| 15194 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15195 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15196 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15197 | } |
| 15198 | |
| 15199 | // Ensure that a client certificate is removed from the SSL client auth |
| 15200 | // cache when: |
| 15201 | // 1) No proxy is involved. |
| 15202 | // 2) TLS False Start is enabled. |
| 15203 | // 3) The initial TLS handshake requests a client certificate. |
| 15204 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15205 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15206 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15207 | request_info.url = GURL("https://www.example.com/"); |
| 15208 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15209 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15210 | request_info.traffic_annotation = |
| 15211 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15212 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15213 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15214 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15215 | |
| 15216 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15217 | // return successfully after reading up to the peer's Certificate message. |
| 15218 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15219 | // enqueue application data to be sent in the same packet as the |
| 15220 | // ChangeCipherSpec and Finished messages. |
| 15221 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15222 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15223 | // Finished messages. If there was an error negotiating with the peer, |
| 15224 | // such as due to the peer requiring a client certificate when none was |
| 15225 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15226 | // called. |
| 15227 | |
| 15228 | // Like the non-False Start case, when a client certificate is requested by |
| 15229 | // the peer, the handshake is aborted during the Connect() call. |
| 15230 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15231 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15232 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15234 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15235 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15236 | |
| 15237 | // When a client certificate is supplied, Connect() will not be aborted |
| 15238 | // when the peer requests the certificate. Instead, the handshake will |
| 15239 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15240 | // the socket. The handshake messages are not processed until Read() is |
| 15241 | // called, which then detects that the handshake was aborted, due to the |
| 15242 | // peer sending a handshake_failure because it requires a client |
| 15243 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15244 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15245 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15247 | MockRead data2_reads[] = { |
| 15248 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15249 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15250 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15251 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15252 | |
| 15253 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15254 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15255 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15256 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15257 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15259 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15260 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15261 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15262 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15263 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15264 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15265 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15267 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15268 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15269 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15270 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15271 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15272 | ssl_data5.cert_request_info = cert_request.get(); |
| 15273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15274 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15275 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15276 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15279 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15280 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15281 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15282 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15283 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15284 | |
| 15285 | // Complete the SSL handshake, which should abort due to requiring a |
| 15286 | // client certificate. |
| 15287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15288 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15289 | |
| 15290 | // Indicate that no certificate should be supplied. From the perspective |
| 15291 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15292 | // certificate, so this is the same as supply a |
| 15293 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15294 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15295 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15296 | |
| 15297 | // Ensure the certificate was added to the client auth cache before |
| 15298 | // allowing the connection to continue restarting. |
| 15299 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15300 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15301 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15302 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15303 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15304 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15305 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15306 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15307 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15308 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15309 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15310 | |
| 15311 | // Ensure that the client certificate is removed from the cache on a |
| 15312 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15313 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15314 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15315 | } |
| 15316 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15317 | // Ensure that a client certificate is removed from the SSL client auth |
| 15318 | // cache when: |
| 15319 | // 1) An HTTPS proxy is involved. |
| 15320 | // 3) The HTTPS proxy requests a client certificate. |
| 15321 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15322 | // proxy. |
| 15323 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15324 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15325 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15326 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15327 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15328 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15329 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15330 | |
| 15331 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15332 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15333 | |
| 15334 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15335 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15336 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15337 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15338 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15339 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15341 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15342 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15343 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15344 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15345 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15347 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15348 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15349 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15350 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15351 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15352 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15353 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15355 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15356 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15357 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15358 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15359 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15360 | requests[0].url = GURL("https://www.example.com/"); |
| 15361 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15362 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15363 | requests[0].traffic_annotation = |
| 15364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15365 | |
| 15366 | requests[1].url = GURL("http://www.example.com/"); |
| 15367 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15368 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15369 | requests[1].traffic_annotation = |
| 15370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15371 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15372 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15373 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15376 | |
| 15377 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15378 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15379 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15380 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15381 | |
| 15382 | // Complete the SSL handshake, which should abort due to requiring a |
| 15383 | // client certificate. |
| 15384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15385 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15386 | |
| 15387 | // Indicate that no certificate should be supplied. From the perspective |
| 15388 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15389 | // certificate, so this is the same as supply a |
| 15390 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15391 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15392 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15393 | |
| 15394 | // Ensure the certificate was added to the client auth cache before |
| 15395 | // allowing the connection to continue restarting. |
| 15396 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15397 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15398 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15399 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15400 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15401 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15402 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15403 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15404 | HostPortPair("www.example.com", 443), &client_cert, |
| 15405 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15406 | |
| 15407 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15408 | // then consume ssl_data3, which should also fail. The result code is |
| 15409 | // checked against what ssl_data3 should return. |
| 15410 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15411 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15412 | |
| 15413 | // Now that the new handshake has failed, ensure that the client |
| 15414 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15415 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15416 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15417 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15418 | HostPortPair("www.example.com", 443), &client_cert, |
| 15419 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15420 | } |
| 15421 | } |
| 15422 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15423 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15424 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15425 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15427 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15428 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15429 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15430 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15431 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15432 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15433 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15434 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15435 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15436 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15437 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15438 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15439 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15440 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15441 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15442 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15443 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15444 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15445 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15446 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15447 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15448 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15449 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15450 | }; |
| 15451 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15452 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15453 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15454 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15455 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15456 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15457 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15458 | HttpRequestInfo request1; |
| 15459 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15460 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15461 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15462 | request1.traffic_annotation = |
| 15463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15464 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15466 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15468 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15469 | |
| 15470 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15471 | ASSERT_TRUE(response); |
| 15472 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15473 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15474 | |
| 15475 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15476 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15477 | EXPECT_EQ("hello!", response_data); |
| 15478 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15479 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15480 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15481 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15483 | |
| 15484 | HttpRequestInfo request2; |
| 15485 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15486 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15487 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15488 | request2.traffic_annotation = |
| 15489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15490 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15491 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15492 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15494 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15495 | |
| 15496 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15497 | ASSERT_TRUE(response); |
| 15498 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15499 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15500 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15501 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15502 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15503 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15504 | } |
| 15505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15506 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15507 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15508 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15509 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15510 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15511 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15512 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15513 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15514 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15515 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15516 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15517 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15518 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15519 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15520 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15521 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15522 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15523 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15524 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15525 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15526 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15527 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15528 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15529 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15530 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15531 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15532 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15533 | }; |
| 15534 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15535 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15536 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15537 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15538 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15539 | |
| 15540 | TestCompletionCallback callback; |
| 15541 | HttpRequestInfo request1; |
| 15542 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15543 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15544 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15545 | request1.traffic_annotation = |
| 15546 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15547 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15548 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15549 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15551 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15552 | |
| 15553 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15554 | ASSERT_TRUE(response); |
| 15555 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15556 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15557 | |
| 15558 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15559 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15560 | EXPECT_EQ("hello!", response_data); |
| 15561 | |
| 15562 | HttpRequestInfo request2; |
| 15563 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15564 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15565 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15566 | request2.traffic_annotation = |
| 15567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15568 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15569 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15570 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15572 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15573 | |
| 15574 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15575 | ASSERT_TRUE(response); |
| 15576 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15577 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15578 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15579 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15580 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15581 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15582 | } |
| 15583 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15584 | // Regression test for https://crbug.com/546991. |
| 15585 | // The server might not be able to serve an IP pooled request, and might send a |
| 15586 | // 421 Misdirected Request response status to indicate this. |
| 15587 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15588 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15589 | // Two hosts resolve to the same IP address. |
| 15590 | const std::string ip_addr = "1.2.3.4"; |
| 15591 | IPAddress ip; |
| 15592 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15593 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15594 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15595 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15596 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15597 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15598 | |
| 15599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15600 | |
| 15601 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15602 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15603 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15604 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15605 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15606 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15607 | spdy::SpdySerializedFrame rst( |
| 15608 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15609 | MockWrite writes1[] = { |
| 15610 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15611 | CreateMockWrite(rst, 6), |
| 15612 | }; |
| 15613 | |
| 15614 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15615 | spdy::SpdySerializedFrame resp1( |
| 15616 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15617 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15618 | spdy::SpdyHeaderBlock response_headers; |
| 15619 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15620 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15621 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15622 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15623 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15624 | |
| 15625 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15626 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15627 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15628 | |
| 15629 | AddSSLSocketData(); |
| 15630 | |
| 15631 | // Retry the second request on a second connection. |
| 15632 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15633 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15634 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15635 | MockWrite writes2[] = { |
| 15636 | CreateMockWrite(req3, 0), |
| 15637 | }; |
| 15638 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15639 | spdy::SpdySerializedFrame resp3( |
| 15640 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15641 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15642 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15643 | MockRead(ASYNC, 0, 3)}; |
| 15644 | |
| 15645 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15646 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15648 | |
| 15649 | AddSSLSocketData(); |
| 15650 | |
| 15651 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15652 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15653 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15654 | EXPECT_THAT(rv, IsOk()); |
| 15655 | |
| 15656 | HttpRequestInfo request1; |
| 15657 | request1.method = "GET"; |
| 15658 | request1.url = GURL("https://www.example.org/"); |
| 15659 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15660 | request1.traffic_annotation = |
| 15661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15662 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15663 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15664 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15665 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15667 | rv = callback.WaitForResult(); |
| 15668 | EXPECT_THAT(rv, IsOk()); |
| 15669 | |
| 15670 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15671 | ASSERT_TRUE(response); |
| 15672 | ASSERT_TRUE(response->headers); |
| 15673 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15674 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15675 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15676 | std::string response_data; |
| 15677 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15678 | EXPECT_EQ("hello!", response_data); |
| 15679 | |
| 15680 | HttpRequestInfo request2; |
| 15681 | request2.method = "GET"; |
| 15682 | request2.url = GURL("https://mail.example.org/"); |
| 15683 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15684 | request2.traffic_annotation = |
| 15685 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15686 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15687 | |
| 15688 | BoundTestNetLog log; |
| 15689 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15691 | rv = callback.WaitForResult(); |
| 15692 | EXPECT_THAT(rv, IsOk()); |
| 15693 | |
| 15694 | response = trans2.GetResponseInfo(); |
| 15695 | ASSERT_TRUE(response); |
| 15696 | ASSERT_TRUE(response->headers); |
| 15697 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15698 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15699 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15700 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15701 | EXPECT_EQ("hello!", response_data); |
| 15702 | |
| 15703 | TestNetLogEntry::List entries; |
| 15704 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15705 | ExpectLogContainsSomewhere( |
| 15706 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15707 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15708 | } |
| 15709 | |
| 15710 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15711 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15712 | // portions of the response. |
| 15713 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15714 | // Two hosts resolve to the same IP address. |
| 15715 | const std::string ip_addr = "1.2.3.4"; |
| 15716 | IPAddress ip; |
| 15717 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15718 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15719 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15720 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15721 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15722 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15723 | |
| 15724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15725 | |
| 15726 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15727 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15728 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15729 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15730 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15731 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15732 | spdy::SpdySerializedFrame rst( |
| 15733 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15734 | MockWrite writes1[] = { |
| 15735 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15736 | CreateMockWrite(rst, 6), |
| 15737 | }; |
| 15738 | |
| 15739 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15740 | spdy::SpdySerializedFrame resp1( |
| 15741 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15742 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15743 | spdy::SpdyHeaderBlock response_headers; |
| 15744 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15745 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15746 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15747 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15748 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15749 | |
| 15750 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15751 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15753 | |
| 15754 | AddSSLSocketData(); |
| 15755 | |
| 15756 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15757 | // Retry again. |
| 15758 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15759 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15760 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15761 | MockWrite writes2[] = { |
| 15762 | CreateMockWrite(req3, 0), |
| 15763 | }; |
| 15764 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15765 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15766 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15767 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15768 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15769 | MockRead(ASYNC, 0, 3)}; |
| 15770 | |
| 15771 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15772 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15773 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15774 | |
| 15775 | AddSSLSocketData(); |
| 15776 | |
| 15777 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15778 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15779 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15780 | EXPECT_THAT(rv, IsOk()); |
| 15781 | |
| 15782 | HttpRequestInfo request1; |
| 15783 | request1.method = "GET"; |
| 15784 | request1.url = GURL("https://www.example.org/"); |
| 15785 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15786 | request1.traffic_annotation = |
| 15787 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15788 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15789 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15790 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15791 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15793 | rv = callback.WaitForResult(); |
| 15794 | EXPECT_THAT(rv, IsOk()); |
| 15795 | |
| 15796 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15797 | ASSERT_TRUE(response); |
| 15798 | ASSERT_TRUE(response->headers); |
| 15799 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15800 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15801 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15802 | std::string response_data; |
| 15803 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15804 | EXPECT_EQ("hello!", response_data); |
| 15805 | |
| 15806 | HttpRequestInfo request2; |
| 15807 | request2.method = "GET"; |
| 15808 | request2.url = GURL("https://mail.example.org/"); |
| 15809 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15810 | request2.traffic_annotation = |
| 15811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15812 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15813 | |
| 15814 | BoundTestNetLog log; |
| 15815 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15817 | rv = callback.WaitForResult(); |
| 15818 | EXPECT_THAT(rv, IsOk()); |
| 15819 | |
| 15820 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15821 | // caller. |
| 15822 | response = trans2.GetResponseInfo(); |
| 15823 | ASSERT_TRUE(response); |
| 15824 | ASSERT_TRUE(response->headers); |
| 15825 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15826 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15827 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15828 | EXPECT_TRUE(response->ssl_info.cert); |
| 15829 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15830 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15831 | } |
| 15832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15833 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15834 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15835 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15836 | session_deps_.host_resolver = |
| 15837 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15839 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15840 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15841 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15842 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15843 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15844 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15845 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15846 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15847 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15848 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15849 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15850 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15851 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15852 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15853 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15854 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15855 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15856 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15857 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15858 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15859 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15860 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15861 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15862 | }; |
| 15863 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15864 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15865 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15866 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15867 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15868 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15869 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15870 | HttpRequestInfo request1; |
| 15871 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15872 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15873 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15874 | request1.traffic_annotation = |
| 15875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15876 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15877 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15878 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15880 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15881 | |
| 15882 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15883 | ASSERT_TRUE(response); |
| 15884 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15885 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15886 | |
| 15887 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15888 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15889 | EXPECT_EQ("hello!", response_data); |
| 15890 | |
| 15891 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15892 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15893 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15895 | |
| 15896 | HttpRequestInfo request2; |
| 15897 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15898 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15899 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15900 | request2.traffic_annotation = |
| 15901 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15902 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15904 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15906 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15907 | |
| 15908 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15909 | ASSERT_TRUE(response); |
| 15910 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15911 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15912 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15913 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15914 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15915 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15916 | } |
| 15917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15918 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15919 | const std::string https_url = "https://www.example.org:8080/"; |
| 15920 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15921 | |
| 15922 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15923 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15924 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15925 | |
| 15926 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15927 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15928 | }; |
| 15929 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 15930 | spdy::SpdySerializedFrame resp1( |
| 15931 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15932 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15933 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15934 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15935 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15936 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15937 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15938 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15939 | |
| 15940 | // HTTP GET for the HTTP URL |
| 15941 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15942 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15943 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15944 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15945 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15946 | }; |
| 15947 | |
| 15948 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15949 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15950 | MockRead(ASYNC, 2, "hello"), |
| 15951 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15952 | }; |
| 15953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15954 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15955 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15956 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15957 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15959 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15960 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15961 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15962 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15963 | |
| 15964 | // Start the first transaction to set up the SpdySession |
| 15965 | HttpRequestInfo request1; |
| 15966 | request1.method = "GET"; |
| 15967 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15968 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15969 | request1.traffic_annotation = |
| 15970 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15971 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15972 | TestCompletionCallback callback1; |
| 15973 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15974 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15975 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15976 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15977 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15978 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15979 | |
| 15980 | // Now, start the HTTP request |
| 15981 | HttpRequestInfo request2; |
| 15982 | request2.method = "GET"; |
| 15983 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15984 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15985 | request2.traffic_annotation = |
| 15986 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15987 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15988 | TestCompletionCallback callback2; |
| 15989 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15990 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15991 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15992 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15993 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15994 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15995 | } |
| 15996 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15997 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15998 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15999 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16000 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16001 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16002 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16003 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16004 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16005 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16006 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16007 | |
| 16008 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16009 | // negotiated. |
| 16010 | StaticSocketDataProvider data; |
| 16011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16012 | |
| 16013 | // 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] | 16014 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16015 | // mocked. This way the request relies on the alternate Job. |
| 16016 | StaticSocketDataProvider data_refused; |
| 16017 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16018 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16019 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16020 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16022 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16023 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16024 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16025 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16026 | http_server_properties->SetHttp2AlternativeService( |
| 16027 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16028 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16029 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16031 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16032 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16033 | request.traffic_annotation = |
| 16034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16035 | TestCompletionCallback callback; |
| 16036 | |
| 16037 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16038 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16039 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16040 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16041 | } |
| 16042 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16043 | // 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] | 16044 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16045 | // succeeds, the request should succeed, even if the latter fails because |
| 16046 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16047 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16048 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16049 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16050 | |
| 16051 | // Negotiate HTTP/1.1 with alternative. |
| 16052 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16053 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16055 | |
| 16056 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16057 | // negotiated. |
| 16058 | StaticSocketDataProvider data; |
| 16059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16060 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16061 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16062 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16063 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16065 | |
| 16066 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16067 | MockWrite("GET / HTTP/1.1\r\n" |
| 16068 | "Host: www.example.org\r\n" |
| 16069 | "Connection: keep-alive\r\n\r\n"), |
| 16070 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16071 | "Host: www.example.org\r\n" |
| 16072 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16073 | }; |
| 16074 | |
| 16075 | MockRead http_reads[] = { |
| 16076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16077 | MockRead("Content-Type: text/html\r\n"), |
| 16078 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16079 | MockRead("foobar"), |
| 16080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16081 | MockRead("Content-Type: text/html\r\n"), |
| 16082 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16083 | MockRead("another"), |
| 16084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16085 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16086 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16087 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16088 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16090 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16091 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16092 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16093 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16094 | http_server_properties->SetHttp2AlternativeService( |
| 16095 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16096 | |
| 16097 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16098 | HttpRequestInfo request1; |
| 16099 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16100 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16101 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16102 | request1.traffic_annotation = |
| 16103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16104 | TestCompletionCallback callback1; |
| 16105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16106 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16107 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16108 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16109 | |
| 16110 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16111 | ASSERT_TRUE(response1); |
| 16112 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16113 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16114 | |
| 16115 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16116 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16117 | EXPECT_EQ("foobar", response_data1); |
| 16118 | |
| 16119 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16120 | // for alternative service. |
| 16121 | EXPECT_TRUE( |
| 16122 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16123 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16124 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16125 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16126 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16127 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16128 | HttpRequestInfo request2; |
| 16129 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16130 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16131 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16132 | request2.traffic_annotation = |
| 16133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16134 | TestCompletionCallback callback2; |
| 16135 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16136 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16137 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16138 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16139 | |
| 16140 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16141 | ASSERT_TRUE(response2); |
| 16142 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16143 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16144 | |
| 16145 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16146 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16147 | EXPECT_EQ("another", response_data2); |
| 16148 | } |
| 16149 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16150 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16151 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16152 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16153 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16154 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16155 | HostPortPair alternative("alternative.example.org", 443); |
| 16156 | std::string origin_url = "https://origin.example.org:443"; |
| 16157 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16158 | |
| 16159 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16160 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16161 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16163 | |
| 16164 | // HTTP/1.1 data for |request1| and |request2|. |
| 16165 | MockWrite http_writes[] = { |
| 16166 | MockWrite( |
| 16167 | "GET / HTTP/1.1\r\n" |
| 16168 | "Host: alternative.example.org\r\n" |
| 16169 | "Connection: keep-alive\r\n\r\n"), |
| 16170 | MockWrite( |
| 16171 | "GET / HTTP/1.1\r\n" |
| 16172 | "Host: alternative.example.org\r\n" |
| 16173 | "Connection: keep-alive\r\n\r\n"), |
| 16174 | }; |
| 16175 | |
| 16176 | MockRead http_reads[] = { |
| 16177 | MockRead( |
| 16178 | "HTTP/1.1 200 OK\r\n" |
| 16179 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16180 | "Content-Length: 40\r\n\r\n" |
| 16181 | "first HTTP/1.1 response from alternative"), |
| 16182 | MockRead( |
| 16183 | "HTTP/1.1 200 OK\r\n" |
| 16184 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16185 | "Content-Length: 41\r\n\r\n" |
| 16186 | "second HTTP/1.1 response from alternative"), |
| 16187 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16188 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16189 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16190 | |
| 16191 | // This test documents that an alternate Job should not pool to an already |
| 16192 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16193 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16194 | StaticSocketDataProvider data_refused; |
| 16195 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16196 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16197 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16198 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16199 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16200 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16201 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16202 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16203 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16204 | http_server_properties->SetHttp2AlternativeService( |
| 16205 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16206 | |
| 16207 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16208 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16209 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16210 | request1.method = "GET"; |
| 16211 | request1.url = GURL(alternative_url); |
| 16212 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16213 | request1.traffic_annotation = |
| 16214 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16215 | TestCompletionCallback callback1; |
| 16216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16217 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16219 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16220 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16221 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16222 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16223 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16224 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16225 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16226 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16227 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16228 | |
| 16229 | // Request for origin.example.org, which has an alternative service. This |
| 16230 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16231 | // 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] | 16232 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16233 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16234 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16235 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16236 | request2.method = "GET"; |
| 16237 | request2.url = GURL(origin_url); |
| 16238 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16239 | request2.traffic_annotation = |
| 16240 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16241 | TestCompletionCallback callback2; |
| 16242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16243 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16244 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16245 | |
| 16246 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16247 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16248 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16249 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16250 | request3.method = "GET"; |
| 16251 | request3.url = GURL(alternative_url); |
| 16252 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16253 | request3.traffic_annotation = |
| 16254 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16255 | TestCompletionCallback callback3; |
| 16256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16257 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16258 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16259 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16260 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16261 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16262 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16263 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16264 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16265 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16266 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16267 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16268 | } |
| 16269 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16270 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16271 | const std::string https_url = "https://www.example.org:8080/"; |
| 16272 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16273 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16274 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16275 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16276 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16277 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16278 | const HostPortPair host_port_pair("www.example.org", 8080); |
Matt Menke | 6e879bd | 2019-03-18 17:26:04 | [diff] [blame] | 16279 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 16280 | nullptr, 0, 1, HttpProxyConnectJob::kH2QuicTunnelPriority, |
| 16281 | host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16282 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16283 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16284 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16285 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16286 | |
| 16287 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16288 | spdy::SpdyHeaderBlock req2_block; |
| 16289 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16290 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16291 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16292 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16293 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16294 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16295 | |
| 16296 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16297 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16298 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16299 | }; |
| 16300 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16301 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16302 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16303 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16304 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16305 | spdy::SpdySerializedFrame body1( |
| 16306 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16307 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16308 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16309 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16310 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16311 | spdy::SpdySerializedFrame resp2( |
| 16312 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16313 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16314 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16315 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16316 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16317 | CreateMockRead(wrapped_resp1, 4), |
| 16318 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16319 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16320 | CreateMockRead(resp2, 8), |
| 16321 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16322 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16323 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16324 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16325 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16326 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16327 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16328 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16329 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16330 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16331 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16332 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16333 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16334 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16335 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16337 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16338 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16340 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16342 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16343 | |
| 16344 | // Start the first transaction to set up the SpdySession |
| 16345 | HttpRequestInfo request1; |
| 16346 | request1.method = "GET"; |
| 16347 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16348 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16349 | request1.traffic_annotation = |
| 16350 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16351 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16352 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16353 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16354 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16355 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16356 | data1.RunUntilPaused(); |
| 16357 | base::RunLoop().RunUntilIdle(); |
| 16358 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16359 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16360 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16361 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16362 | LoadTimingInfo load_timing_info1; |
| 16363 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16364 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16365 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16366 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16367 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16368 | HttpRequestInfo request2; |
| 16369 | request2.method = "GET"; |
| 16370 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16371 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16372 | request2.traffic_annotation = |
| 16373 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16374 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16375 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16376 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16377 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16378 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16379 | data1.RunUntilPaused(); |
| 16380 | base::RunLoop().RunUntilIdle(); |
| 16381 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16382 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16383 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16384 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16385 | |
| 16386 | LoadTimingInfo load_timing_info2; |
| 16387 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16388 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16389 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16390 | // HTTP requests over a SPDY session should have a different connection |
| 16391 | // socket_log_id than requests over a tunnel. |
| 16392 | 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] | 16393 | } |
| 16394 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16395 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16396 | // that we do not pool other origins that resolve to the same IP when |
| 16397 | // the certificate does not match the new origin. |
| 16398 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16399 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16400 | const std::string url1 = "http://www.example.org/"; |
| 16401 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16402 | const std::string ip_addr = "1.2.3.4"; |
| 16403 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16404 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16405 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16406 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16407 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16408 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16409 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16410 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16411 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16412 | |
| 16413 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16414 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16415 | }; |
| 16416 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16417 | spdy::SpdySerializedFrame resp1( |
| 16418 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16419 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16420 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16421 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16422 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16423 | }; |
| 16424 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16425 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16426 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16427 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16428 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16429 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16430 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16431 | |
| 16432 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16433 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16434 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16435 | |
| 16436 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16437 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16438 | }; |
| 16439 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16440 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16441 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16442 | spdy::SpdySerializedFrame body2( |
| 16443 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16444 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16445 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16446 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16447 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16448 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16449 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16450 | |
| 16451 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16452 | // all others direct. |
| 16453 | ProxyConfig proxy_config; |
| 16454 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16455 | session_deps_.proxy_resolution_service = |
| 16456 | std::make_unique<ProxyResolutionService>( |
| 16457 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16458 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16459 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16460 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16461 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16462 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16463 | // Load a valid cert. Note, that this does not need to |
| 16464 | // be valid for proxy because the MockSSLClientSocket does |
| 16465 | // not actually verify it. But SpdySession will use this |
| 16466 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16467 | ssl1.ssl_info.cert = |
| 16468 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16469 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16471 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16472 | |
| 16473 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16474 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16475 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16476 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16477 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16478 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16479 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16480 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16482 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16483 | |
| 16484 | // Start the first transaction to set up the SpdySession |
| 16485 | HttpRequestInfo request1; |
| 16486 | request1.method = "GET"; |
| 16487 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16488 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16489 | request1.traffic_annotation = |
| 16490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16491 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16492 | TestCompletionCallback callback1; |
| 16493 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16494 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16495 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16496 | data1.RunUntilPaused(); |
| 16497 | base::RunLoop().RunUntilIdle(); |
| 16498 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16499 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16500 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16501 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16502 | |
| 16503 | // Now, start the HTTP request |
| 16504 | HttpRequestInfo request2; |
| 16505 | request2.method = "GET"; |
| 16506 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16507 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16508 | request2.traffic_annotation = |
| 16509 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16510 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16511 | TestCompletionCallback callback2; |
| 16512 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16513 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16514 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16515 | |
| 16516 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16517 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16518 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16519 | } |
| 16520 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16521 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16522 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16523 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16524 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16525 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16526 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16527 | |
| 16528 | MockRead reads1[] = { |
| 16529 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16530 | }; |
| 16531 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16532 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16533 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16534 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16535 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16536 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16537 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16538 | }; |
| 16539 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16540 | spdy::SpdySerializedFrame resp2( |
| 16541 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16542 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16543 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16544 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16545 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16546 | }; |
| 16547 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16548 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16549 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16550 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16551 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16552 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16553 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16554 | |
| 16555 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16556 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16558 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16559 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16560 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16561 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16562 | |
| 16563 | // Start the first transaction to set up the SpdySession and verify that |
| 16564 | // connection was closed. |
| 16565 | HttpRequestInfo request1; |
| 16566 | request1.method = "GET"; |
| 16567 | request1.url = GURL(https_url); |
| 16568 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16569 | request1.traffic_annotation = |
| 16570 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16571 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16572 | TestCompletionCallback callback1; |
| 16573 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16574 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16575 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16576 | |
| 16577 | // Now, start the second request and make sure it succeeds. |
| 16578 | HttpRequestInfo request2; |
| 16579 | request2.method = "GET"; |
| 16580 | request2.url = GURL(https_url); |
| 16581 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16582 | request2.traffic_annotation = |
| 16583 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16584 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16585 | TestCompletionCallback callback2; |
| 16586 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16587 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16588 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16589 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16590 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16591 | } |
| 16592 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16593 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16594 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16595 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16596 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16597 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16598 | |
| 16599 | // Use two different hosts with different IPs so they don't get pooled. |
| 16600 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16601 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16603 | |
| 16604 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16605 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16606 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16607 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16610 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16611 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16612 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16613 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16614 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16615 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16616 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16617 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16618 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16619 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16620 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16621 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16622 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16623 | }; |
| 16624 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16625 | // Use a separate test instance for the separate SpdySession that will be |
| 16626 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16627 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16628 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16629 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16630 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16631 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16632 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16633 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16634 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16635 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16636 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 16637 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16638 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16639 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16640 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16641 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16642 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16643 | }; |
| 16644 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16645 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16646 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16647 | |
| 16648 | MockWrite http_write[] = { |
| 16649 | MockWrite("GET / HTTP/1.1\r\n" |
| 16650 | "Host: www.a.com\r\n" |
| 16651 | "Connection: keep-alive\r\n\r\n"), |
| 16652 | }; |
| 16653 | |
| 16654 | MockRead http_read[] = { |
| 16655 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16656 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16657 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16658 | MockRead("hello!"), |
| 16659 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16660 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16661 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16662 | |
| 16663 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16664 | SpdySessionKey spdy_session_key_a( |
| 16665 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16666 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16667 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16668 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16669 | |
| 16670 | TestCompletionCallback callback; |
| 16671 | HttpRequestInfo request1; |
| 16672 | request1.method = "GET"; |
| 16673 | request1.url = GURL("https://www.a.com/"); |
| 16674 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16675 | request1.traffic_annotation = |
| 16676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16677 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16678 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16680 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16682 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16683 | |
| 16684 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16685 | ASSERT_TRUE(response); |
| 16686 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16687 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16688 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16689 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16690 | |
| 16691 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16692 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16693 | EXPECT_EQ("hello!", response_data); |
| 16694 | trans.reset(); |
| 16695 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16696 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16697 | |
| 16698 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16699 | SpdySessionKey spdy_session_key_b( |
| 16700 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16701 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16702 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16703 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16704 | HttpRequestInfo request2; |
| 16705 | request2.method = "GET"; |
| 16706 | request2.url = GURL("https://www.b.com/"); |
| 16707 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16708 | request2.traffic_annotation = |
| 16709 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16710 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16711 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16713 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16715 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16716 | |
| 16717 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16718 | ASSERT_TRUE(response); |
| 16719 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16720 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16721 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16722 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16723 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16724 | EXPECT_EQ("hello!", response_data); |
| 16725 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16726 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16727 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16728 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16729 | |
| 16730 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16731 | SpdySessionKey spdy_session_key_a1( |
| 16732 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16733 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16734 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16735 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16736 | HttpRequestInfo request3; |
| 16737 | request3.method = "GET"; |
| 16738 | request3.url = GURL("http://www.a.com/"); |
| 16739 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16740 | request3.traffic_annotation = |
| 16741 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16742 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16743 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16744 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16745 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16747 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16748 | |
| 16749 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16750 | ASSERT_TRUE(response); |
| 16751 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16752 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16753 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16754 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16755 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16756 | EXPECT_EQ("hello!", response_data); |
| 16757 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16758 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16759 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16760 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16761 | } |
| 16762 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16763 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16764 | HttpRequestInfo request; |
| 16765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16766 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16767 | request.traffic_annotation = |
| 16768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16769 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16772 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16773 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16774 | StaticSocketDataProvider data; |
| 16775 | data.set_connect_data(mock_connect); |
| 16776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16777 | |
| 16778 | TestCompletionCallback callback; |
| 16779 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16780 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16782 | |
| 16783 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16784 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16785 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16786 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16787 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16788 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16789 | |
| 16790 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16791 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16792 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16793 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16794 | |
| 16795 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16796 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16797 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16798 | } |
| 16799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16800 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16801 | HttpRequestInfo request; |
| 16802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16803 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16804 | request.traffic_annotation = |
| 16805 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16806 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16809 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16810 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16811 | StaticSocketDataProvider data; |
| 16812 | data.set_connect_data(mock_connect); |
| 16813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16814 | |
| 16815 | TestCompletionCallback callback; |
| 16816 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16819 | |
| 16820 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16821 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16822 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16823 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16824 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16825 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16826 | |
| 16827 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16828 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16829 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16830 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16831 | |
| 16832 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16833 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16834 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16835 | } |
| 16836 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16837 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16838 | HttpRequestInfo request; |
| 16839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16840 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16841 | request.traffic_annotation = |
| 16842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16846 | |
| 16847 | MockWrite data_writes[] = { |
| 16848 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16849 | }; |
| 16850 | MockRead data_reads[] = { |
| 16851 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16852 | }; |
| 16853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16854 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16856 | |
| 16857 | TestCompletionCallback callback; |
| 16858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16861 | |
| 16862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16863 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16864 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16865 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16866 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16867 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16868 | } |
| 16869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16870 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16871 | HttpRequestInfo request; |
| 16872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16873 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16874 | request.traffic_annotation = |
| 16875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16879 | |
| 16880 | MockWrite data_writes[] = { |
| 16881 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16882 | }; |
| 16883 | MockRead data_reads[] = { |
| 16884 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16885 | }; |
| 16886 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16887 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16888 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16889 | |
| 16890 | TestCompletionCallback callback; |
| 16891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16892 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16894 | |
| 16895 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16896 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16897 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16898 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16899 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16900 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16901 | } |
| 16902 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16903 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16904 | HttpRequestInfo request; |
| 16905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16906 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16907 | request.traffic_annotation = |
| 16908 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16912 | |
| 16913 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16914 | MockWrite( |
| 16915 | "GET / HTTP/1.1\r\n" |
| 16916 | "Host: www.example.org\r\n" |
| 16917 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16918 | }; |
| 16919 | MockRead data_reads[] = { |
| 16920 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16921 | }; |
| 16922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16923 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16925 | |
| 16926 | TestCompletionCallback callback; |
| 16927 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16928 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16930 | |
| 16931 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16932 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16933 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16934 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16935 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16937 | } |
| 16938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16939 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16940 | HttpRequestInfo request; |
| 16941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16942 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16943 | request.traffic_annotation = |
| 16944 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16945 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16947 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16948 | |
| 16949 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16950 | MockWrite( |
| 16951 | "GET / HTTP/1.1\r\n" |
| 16952 | "Host: www.example.org\r\n" |
| 16953 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16954 | }; |
| 16955 | MockRead data_reads[] = { |
| 16956 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16957 | }; |
| 16958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16959 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16961 | |
| 16962 | TestCompletionCallback callback; |
| 16963 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16964 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16966 | |
| 16967 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16968 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16969 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16970 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16971 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16972 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16973 | } |
| 16974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16975 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16976 | HttpRequestInfo request; |
| 16977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16978 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16979 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16980 | request.traffic_annotation = |
| 16981 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16982 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16984 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16985 | |
| 16986 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16987 | MockWrite( |
| 16988 | "GET / HTTP/1.1\r\n" |
| 16989 | "Host: www.example.org\r\n" |
| 16990 | "Connection: keep-alive\r\n" |
| 16991 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16992 | }; |
| 16993 | MockRead data_reads[] = { |
| 16994 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16995 | "Content-Length: 5\r\n\r\n" |
| 16996 | "hello"), |
| 16997 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16998 | }; |
| 16999 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17000 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17002 | |
| 17003 | TestCompletionCallback callback; |
| 17004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17005 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17007 | |
| 17008 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17010 | |
| 17011 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17012 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17013 | std::string foo; |
| 17014 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17015 | EXPECT_EQ("bar", foo); |
| 17016 | } |
| 17017 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17018 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17019 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17020 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17021 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17022 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17023 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17024 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17025 | |
| 17026 | // Set up SSL request. |
| 17027 | |
| 17028 | HttpRequestInfo ssl_request; |
| 17029 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17030 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17031 | ssl_request.traffic_annotation = |
| 17032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17033 | |
| 17034 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17035 | MockWrite( |
| 17036 | "GET / HTTP/1.1\r\n" |
| 17037 | "Host: www.example.org\r\n" |
| 17038 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17039 | }; |
| 17040 | MockRead ssl_reads[] = { |
| 17041 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17042 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17043 | MockRead("hello world"), |
| 17044 | MockRead(SYNCHRONOUS, OK), |
| 17045 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17046 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17047 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17048 | |
| 17049 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17050 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17051 | |
| 17052 | // Set up HTTP request. |
| 17053 | |
| 17054 | HttpRequestInfo http_request; |
| 17055 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17056 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17057 | http_request.traffic_annotation = |
| 17058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17059 | |
| 17060 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17061 | MockWrite( |
| 17062 | "GET / HTTP/1.1\r\n" |
| 17063 | "Host: www.example.org\r\n" |
| 17064 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17065 | }; |
| 17066 | MockRead http_reads[] = { |
| 17067 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17068 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17069 | MockRead("falafel"), |
| 17070 | MockRead(SYNCHRONOUS, OK), |
| 17071 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17072 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17073 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17074 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17076 | |
| 17077 | // Start the SSL request. |
| 17078 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17079 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17080 | ASSERT_EQ(ERR_IO_PENDING, |
| 17081 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17082 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17083 | |
| 17084 | // Start the HTTP request. Pool should stall. |
| 17085 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17086 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17087 | ASSERT_EQ(ERR_IO_PENDING, |
| 17088 | http_trans.Start(&http_request, http_callback.callback(), |
| 17089 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17090 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17091 | |
| 17092 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17093 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17094 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17095 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17096 | EXPECT_EQ("hello world", response_data); |
| 17097 | |
| 17098 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17099 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17100 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17101 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17102 | |
| 17103 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17104 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17105 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17106 | EXPECT_EQ("falafel", response_data); |
| 17107 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17108 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17109 | } |
| 17110 | |
| 17111 | // Tests that when a SSL connection is established but there's no corresponding |
| 17112 | // request that needs it, the new socket is closed if the transport socket pool |
| 17113 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17114 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17115 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17116 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17117 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17118 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17119 | |
| 17120 | // Set up an ssl request. |
| 17121 | |
| 17122 | HttpRequestInfo ssl_request; |
| 17123 | ssl_request.method = "GET"; |
| 17124 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17125 | ssl_request.traffic_annotation = |
| 17126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17127 | |
| 17128 | // No data will be sent on the SSL socket. |
| 17129 | StaticSocketDataProvider ssl_data; |
| 17130 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17131 | |
| 17132 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17133 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17134 | |
| 17135 | // Set up HTTP request. |
| 17136 | |
| 17137 | HttpRequestInfo http_request; |
| 17138 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17139 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17140 | http_request.traffic_annotation = |
| 17141 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17142 | |
| 17143 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17144 | MockWrite( |
| 17145 | "GET / HTTP/1.1\r\n" |
| 17146 | "Host: www.example.org\r\n" |
| 17147 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17148 | }; |
| 17149 | MockRead http_reads[] = { |
| 17150 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17151 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17152 | MockRead("falafel"), |
| 17153 | MockRead(SYNCHRONOUS, OK), |
| 17154 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17155 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17156 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17159 | |
| 17160 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17161 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17162 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17163 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17164 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17165 | |
| 17166 | // Start the HTTP request. Pool should stall. |
| 17167 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17168 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17169 | ASSERT_EQ(ERR_IO_PENDING, |
| 17170 | http_trans.Start(&http_request, http_callback.callback(), |
| 17171 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17172 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17173 | |
| 17174 | // The SSL connection will automatically be closed once the connection is |
| 17175 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17176 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17177 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17178 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17179 | EXPECT_EQ("falafel", response_data); |
| 17180 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17181 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17182 | } |
| 17183 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17184 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17185 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17186 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17187 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17188 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17189 | |
| 17190 | HttpRequestInfo request; |
| 17191 | request.method = "POST"; |
| 17192 | request.url = GURL("http://www.foo.com/"); |
| 17193 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17194 | request.traffic_annotation = |
| 17195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17196 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17198 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17199 | // Send headers successfully, but get an error while sending the body. |
| 17200 | MockWrite data_writes[] = { |
| 17201 | MockWrite("POST / HTTP/1.1\r\n" |
| 17202 | "Host: www.foo.com\r\n" |
| 17203 | "Connection: keep-alive\r\n" |
| 17204 | "Content-Length: 3\r\n\r\n"), |
| 17205 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17206 | }; |
| 17207 | |
| 17208 | MockRead data_reads[] = { |
| 17209 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17210 | MockRead("hello world"), |
| 17211 | MockRead(SYNCHRONOUS, OK), |
| 17212 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17213 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17215 | |
| 17216 | TestCompletionCallback callback; |
| 17217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17218 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17220 | |
| 17221 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17222 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17224 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17225 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17226 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17227 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17228 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17229 | |
| 17230 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17231 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17232 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17233 | EXPECT_EQ("hello world", response_data); |
| 17234 | } |
| 17235 | |
| 17236 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17237 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17238 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17239 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17240 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17241 | MockWrite data_writes[] = { |
| 17242 | MockWrite("GET / HTTP/1.1\r\n" |
| 17243 | "Host: www.foo.com\r\n" |
| 17244 | "Connection: keep-alive\r\n\r\n"), |
| 17245 | MockWrite("POST / HTTP/1.1\r\n" |
| 17246 | "Host: www.foo.com\r\n" |
| 17247 | "Connection: keep-alive\r\n" |
| 17248 | "Content-Length: 3\r\n\r\n"), |
| 17249 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17250 | }; |
| 17251 | |
| 17252 | MockRead data_reads[] = { |
| 17253 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17254 | "Content-Length: 14\r\n\r\n"), |
| 17255 | MockRead("first response"), |
| 17256 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17257 | "Content-Length: 15\r\n\r\n"), |
| 17258 | MockRead("second response"), |
| 17259 | MockRead(SYNCHRONOUS, OK), |
| 17260 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17261 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17262 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17263 | |
| 17264 | TestCompletionCallback callback; |
| 17265 | HttpRequestInfo request1; |
| 17266 | request1.method = "GET"; |
| 17267 | request1.url = GURL("http://www.foo.com/"); |
| 17268 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17269 | request1.traffic_annotation = |
| 17270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17271 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17272 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17273 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17274 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17276 | |
| 17277 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17278 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17279 | |
| 17280 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17281 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17282 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17283 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17284 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17285 | |
| 17286 | std::string response_data1; |
| 17287 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17289 | EXPECT_EQ("first response", response_data1); |
| 17290 | // Delete the transaction to release the socket back into the socket pool. |
| 17291 | trans1.reset(); |
| 17292 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17293 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17294 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17295 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17296 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17297 | |
| 17298 | HttpRequestInfo request2; |
| 17299 | request2.method = "POST"; |
| 17300 | request2.url = GURL("http://www.foo.com/"); |
| 17301 | request2.upload_data_stream = &upload_data_stream; |
| 17302 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17303 | request2.traffic_annotation = |
| 17304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17306 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17307 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17309 | |
| 17310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17313 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17314 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17315 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17316 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17317 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17318 | |
| 17319 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17320 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17321 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17322 | EXPECT_EQ("second response", response_data2); |
| 17323 | } |
| 17324 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17325 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17326 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17327 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17328 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17329 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17330 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17331 | |
| 17332 | HttpRequestInfo request; |
| 17333 | request.method = "POST"; |
| 17334 | request.url = GURL("http://www.foo.com/"); |
| 17335 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17336 | request.traffic_annotation = |
| 17337 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17338 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17341 | // Send headers successfully, but get an error while sending the body. |
| 17342 | MockWrite data_writes[] = { |
| 17343 | MockWrite("POST / HTTP/1.1\r\n" |
| 17344 | "Host: www.foo.com\r\n" |
| 17345 | "Connection: keep-alive\r\n" |
| 17346 | "Content-Length: 3\r\n\r\n" |
| 17347 | "fo"), |
| 17348 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17349 | }; |
| 17350 | |
| 17351 | MockRead data_reads[] = { |
| 17352 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17353 | MockRead("hello world"), |
| 17354 | MockRead(SYNCHRONOUS, OK), |
| 17355 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17356 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17357 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17358 | |
| 17359 | TestCompletionCallback callback; |
| 17360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17361 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17363 | |
| 17364 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17365 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17368 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17369 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17370 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17371 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17372 | |
| 17373 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17374 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17376 | EXPECT_EQ("hello world", response_data); |
| 17377 | } |
| 17378 | |
| 17379 | // This tests the more common case than the previous test, where headers and |
| 17380 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17381 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17382 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | |
| 17384 | HttpRequestInfo request; |
| 17385 | request.method = "POST"; |
| 17386 | request.url = GURL("http://www.foo.com/"); |
| 17387 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17388 | request.traffic_annotation = |
| 17389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17390 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17393 | // Send headers successfully, but get an error while sending the body. |
| 17394 | MockWrite data_writes[] = { |
| 17395 | MockWrite("POST / HTTP/1.1\r\n" |
| 17396 | "Host: www.foo.com\r\n" |
| 17397 | "Connection: keep-alive\r\n" |
| 17398 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17399 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17400 | }; |
| 17401 | |
| 17402 | MockRead data_reads[] = { |
| 17403 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17404 | MockRead("hello world"), |
| 17405 | MockRead(SYNCHRONOUS, OK), |
| 17406 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17407 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17408 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17409 | |
| 17410 | TestCompletionCallback callback; |
| 17411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17412 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17414 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17415 | // they can't be merged with the body in a single send. Not currently |
| 17416 | // necessary since a chunked body is never merged with headers, but this makes |
| 17417 | // the test more future proof. |
| 17418 | base::RunLoop().RunUntilIdle(); |
| 17419 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17420 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17421 | |
| 17422 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17424 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17425 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17426 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17427 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17428 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17429 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17430 | |
| 17431 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17432 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17434 | EXPECT_EQ("hello world", response_data); |
| 17435 | } |
| 17436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17437 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17438 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17439 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17440 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17441 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17442 | |
| 17443 | HttpRequestInfo request; |
| 17444 | request.method = "POST"; |
| 17445 | request.url = GURL("http://www.foo.com/"); |
| 17446 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17447 | request.traffic_annotation = |
| 17448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17452 | |
| 17453 | MockWrite data_writes[] = { |
| 17454 | MockWrite("POST / HTTP/1.1\r\n" |
| 17455 | "Host: www.foo.com\r\n" |
| 17456 | "Connection: keep-alive\r\n" |
| 17457 | "Content-Length: 3\r\n\r\n"), |
| 17458 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17459 | }; |
| 17460 | |
| 17461 | MockRead data_reads[] = { |
| 17462 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17463 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17464 | MockRead("hello world"), |
| 17465 | MockRead(SYNCHRONOUS, OK), |
| 17466 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17467 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17468 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17469 | |
| 17470 | TestCompletionCallback callback; |
| 17471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17472 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17474 | |
| 17475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17479 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17481 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17482 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17483 | |
| 17484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17485 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17487 | EXPECT_EQ("hello world", response_data); |
| 17488 | } |
| 17489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17490 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17491 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17492 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17493 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17494 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17495 | |
| 17496 | HttpRequestInfo request; |
| 17497 | request.method = "POST"; |
| 17498 | request.url = GURL("http://www.foo.com/"); |
| 17499 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17500 | request.traffic_annotation = |
| 17501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17505 | // Send headers successfully, but get an error while sending the body. |
| 17506 | MockWrite data_writes[] = { |
| 17507 | MockWrite("POST / HTTP/1.1\r\n" |
| 17508 | "Host: www.foo.com\r\n" |
| 17509 | "Connection: keep-alive\r\n" |
| 17510 | "Content-Length: 3\r\n\r\n"), |
| 17511 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17512 | }; |
| 17513 | |
| 17514 | MockRead data_reads[] = { |
| 17515 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17516 | MockRead("hello world"), |
| 17517 | MockRead(SYNCHRONOUS, OK), |
| 17518 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17519 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17520 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17521 | |
| 17522 | TestCompletionCallback callback; |
| 17523 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17524 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17525 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17526 | |
| 17527 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17528 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17529 | } |
| 17530 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17531 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17532 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17533 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17534 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17535 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17536 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17537 | |
| 17538 | HttpRequestInfo request; |
| 17539 | request.method = "POST"; |
| 17540 | request.url = GURL("http://www.foo.com/"); |
| 17541 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17542 | request.traffic_annotation = |
| 17543 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17544 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17547 | // Send headers successfully, but get an error while sending the body. |
| 17548 | MockWrite data_writes[] = { |
| 17549 | MockWrite("POST / HTTP/1.1\r\n" |
| 17550 | "Host: www.foo.com\r\n" |
| 17551 | "Connection: keep-alive\r\n" |
| 17552 | "Content-Length: 3\r\n\r\n"), |
| 17553 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17554 | }; |
| 17555 | |
| 17556 | MockRead data_reads[] = { |
| 17557 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17558 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17559 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17560 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17561 | MockRead(SYNCHRONOUS, OK), |
| 17562 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17563 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17565 | |
| 17566 | TestCompletionCallback callback; |
| 17567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17568 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17569 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17570 | |
| 17571 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17572 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17573 | } |
| 17574 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17575 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17576 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17577 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17578 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17579 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17580 | |
| 17581 | HttpRequestInfo request; |
| 17582 | request.method = "POST"; |
| 17583 | request.url = GURL("http://www.foo.com/"); |
| 17584 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17585 | request.traffic_annotation = |
| 17586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17589 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17590 | // Send headers successfully, but get an error while sending the body. |
| 17591 | MockWrite data_writes[] = { |
| 17592 | MockWrite("POST / HTTP/1.1\r\n" |
| 17593 | "Host: www.foo.com\r\n" |
| 17594 | "Connection: keep-alive\r\n" |
| 17595 | "Content-Length: 3\r\n\r\n"), |
| 17596 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17597 | }; |
| 17598 | |
| 17599 | MockRead data_reads[] = { |
| 17600 | MockRead("HTTP 0.9 rocks!"), |
| 17601 | MockRead(SYNCHRONOUS, OK), |
| 17602 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17603 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17605 | |
| 17606 | TestCompletionCallback callback; |
| 17607 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17608 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17610 | |
| 17611 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17612 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17613 | } |
| 17614 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17615 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17616 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17617 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17618 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17619 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17620 | |
| 17621 | HttpRequestInfo request; |
| 17622 | request.method = "POST"; |
| 17623 | request.url = GURL("http://www.foo.com/"); |
| 17624 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17625 | request.traffic_annotation = |
| 17626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17629 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17630 | // Send headers successfully, but get an error while sending the body. |
| 17631 | MockWrite data_writes[] = { |
| 17632 | MockWrite("POST / HTTP/1.1\r\n" |
| 17633 | "Host: www.foo.com\r\n" |
| 17634 | "Connection: keep-alive\r\n" |
| 17635 | "Content-Length: 3\r\n\r\n"), |
| 17636 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17637 | }; |
| 17638 | |
| 17639 | MockRead data_reads[] = { |
| 17640 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17641 | MockRead(SYNCHRONOUS, OK), |
| 17642 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17643 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17645 | |
| 17646 | TestCompletionCallback callback; |
| 17647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17650 | |
| 17651 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17652 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17653 | } |
| 17654 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17655 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17656 | |
| 17657 | namespace { |
| 17658 | |
| 17659 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17660 | headers->SetHeader("Connection", "Upgrade"); |
| 17661 | headers->SetHeader("Upgrade", "websocket"); |
| 17662 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17663 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17664 | } |
| 17665 | |
| 17666 | } // namespace |
| 17667 | |
| 17668 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17669 | for (bool secure : {true, false}) { |
| 17670 | MockWrite data_writes[] = { |
| 17671 | MockWrite("GET / HTTP/1.1\r\n" |
| 17672 | "Host: www.example.org\r\n" |
| 17673 | "Connection: Upgrade\r\n" |
| 17674 | "Upgrade: websocket\r\n" |
| 17675 | "Origin: http://www.example.org\r\n" |
| 17676 | "Sec-WebSocket-Version: 13\r\n" |
| 17677 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17678 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17679 | "client_max_window_bits\r\n\r\n")}; |
| 17680 | |
| 17681 | MockRead data_reads[] = { |
| 17682 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17683 | "Upgrade: websocket\r\n" |
| 17684 | "Connection: Upgrade\r\n" |
| 17685 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17686 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17687 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17689 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17690 | if (secure) |
| 17691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17692 | |
| 17693 | HttpRequestInfo request; |
| 17694 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17695 | request.url = |
| 17696 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17697 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17698 | request.traffic_annotation = |
| 17699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17700 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17701 | TestWebSocketHandshakeStreamCreateHelper |
| 17702 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17703 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17705 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17706 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17707 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17708 | |
| 17709 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17712 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17713 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17714 | ASSERT_TRUE(stream_request); |
| 17715 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17716 | stream_request->websocket_handshake_stream_create_helper()); |
| 17717 | |
| 17718 | rv = callback.WaitForResult(); |
| 17719 | EXPECT_THAT(rv, IsOk()); |
| 17720 | |
| 17721 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17722 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17723 | } |
| 17724 | } |
| 17725 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17726 | // Verify that proxy headers are not sent to the destination server when |
| 17727 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17728 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17729 | HttpRequestInfo request; |
| 17730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17731 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17732 | request.traffic_annotation = |
| 17733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17734 | AddWebSocketHeaders(&request.extra_headers); |
| 17735 | |
| 17736 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17737 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17738 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17739 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17740 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17741 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17742 | |
| 17743 | // Since a proxy is configured, try to establish a tunnel. |
| 17744 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17745 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17746 | "Host: www.example.org:443\r\n" |
| 17747 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17748 | |
| 17749 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17750 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17751 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17752 | "Host: www.example.org:443\r\n" |
| 17753 | "Proxy-Connection: keep-alive\r\n" |
| 17754 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17755 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17756 | MockWrite("GET / HTTP/1.1\r\n" |
| 17757 | "Host: www.example.org\r\n" |
| 17758 | "Connection: Upgrade\r\n" |
| 17759 | "Upgrade: websocket\r\n" |
| 17760 | "Origin: http://www.example.org\r\n" |
| 17761 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17762 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17763 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17764 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17765 | |
| 17766 | // The proxy responds to the connect with a 407, using a persistent |
| 17767 | // connection. |
| 17768 | MockRead data_reads[] = { |
| 17769 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17770 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17771 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17772 | "Content-Length: 0\r\n" |
| 17773 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17774 | |
| 17775 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17776 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17777 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17778 | "Upgrade: websocket\r\n" |
| 17779 | "Connection: Upgrade\r\n" |
| 17780 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17781 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17782 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17784 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17785 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17786 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17787 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17788 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17789 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17790 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17791 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17792 | &websocket_stream_create_helper); |
| 17793 | |
| 17794 | { |
| 17795 | TestCompletionCallback callback; |
| 17796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17797 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17799 | |
| 17800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17801 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17802 | } |
| 17803 | |
| 17804 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17805 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17806 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17807 | EXPECT_EQ(407, response->headers->response_code()); |
| 17808 | |
| 17809 | { |
| 17810 | TestCompletionCallback callback; |
| 17811 | |
| 17812 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17813 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17815 | |
| 17816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17817 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17818 | } |
| 17819 | |
| 17820 | response = trans->GetResponseInfo(); |
| 17821 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17822 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17823 | |
| 17824 | EXPECT_EQ(101, response->headers->response_code()); |
| 17825 | |
| 17826 | trans.reset(); |
| 17827 | session->CloseAllConnections(); |
| 17828 | } |
| 17829 | |
| 17830 | // Verify that proxy headers are not sent to the destination server when |
| 17831 | // establishing a tunnel for an insecure WebSocket connection. |
| 17832 | // This requires the authentication info to be injected into the auth cache |
| 17833 | // due to crbug.com/395064 |
| 17834 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17835 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17836 | HttpRequestInfo request; |
| 17837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17838 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17839 | request.traffic_annotation = |
| 17840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17841 | AddWebSocketHeaders(&request.extra_headers); |
| 17842 | |
| 17843 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17844 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17845 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17846 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17849 | |
| 17850 | MockWrite data_writes[] = { |
| 17851 | // Try to establish a tunnel for the WebSocket connection, with |
| 17852 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17853 | // they cannot and will not use the same TCP/IP connection as the |
| 17854 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17855 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17856 | "Host: www.example.org:80\r\n" |
| 17857 | "Proxy-Connection: keep-alive\r\n" |
| 17858 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17859 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17860 | MockWrite("GET / HTTP/1.1\r\n" |
| 17861 | "Host: www.example.org\r\n" |
| 17862 | "Connection: Upgrade\r\n" |
| 17863 | "Upgrade: websocket\r\n" |
| 17864 | "Origin: http://www.example.org\r\n" |
| 17865 | "Sec-WebSocket-Version: 13\r\n" |
| 17866 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17867 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17868 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17869 | |
| 17870 | MockRead data_reads[] = { |
| 17871 | // HTTP CONNECT with credentials. |
| 17872 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17873 | |
| 17874 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17875 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17876 | "Upgrade: websocket\r\n" |
| 17877 | "Connection: Upgrade\r\n" |
| 17878 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17879 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17880 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17881 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17882 | |
| 17883 | session->http_auth_cache()->Add( |
| 17884 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17885 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17886 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17887 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17888 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17889 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17890 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17891 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17892 | &websocket_stream_create_helper); |
| 17893 | |
| 17894 | TestCompletionCallback callback; |
| 17895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17896 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17898 | |
| 17899 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17900 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17901 | |
| 17902 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17903 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17904 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17905 | |
| 17906 | EXPECT_EQ(101, response->headers->response_code()); |
| 17907 | |
| 17908 | trans.reset(); |
| 17909 | session->CloseAllConnections(); |
| 17910 | } |
| 17911 | |
Matt Menke | 1d6093e3 | 2019-03-22 17:33:43 | [diff] [blame] | 17912 | // WebSockets over QUIC is not supported, including over QUIC proxies. |
| 17913 | TEST_F(HttpNetworkTransactionTest, WebSocketNotSentOverQuicProxy) { |
| 17914 | for (bool secure : {true, false}) { |
| 17915 | SCOPED_TRACE(secure); |
| 17916 | session_deps_.proxy_resolution_service = |
| 17917 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17918 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17919 | session_deps_.enable_quic = true; |
| 17920 | |
| 17921 | HttpRequestInfo request; |
| 17922 | request.url = |
| 17923 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17924 | AddWebSocketHeaders(&request.extra_headers); |
| 17925 | request.traffic_annotation = |
| 17926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17927 | |
| 17928 | TestWebSocketHandshakeStreamCreateHelper |
| 17929 | websocket_handshake_stream_create_helper; |
| 17930 | |
| 17931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17932 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17933 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17934 | &websocket_handshake_stream_create_helper); |
| 17935 | |
| 17936 | TestCompletionCallback callback; |
| 17937 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17939 | |
| 17940 | rv = callback.WaitForResult(); |
| 17941 | EXPECT_THAT(rv, IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17942 | } |
| 17943 | } |
| 17944 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17945 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17947 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17948 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17949 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17950 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17951 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17952 | |
| 17953 | HttpRequestInfo request; |
| 17954 | request.method = "POST"; |
| 17955 | request.url = GURL("http://www.foo.com/"); |
| 17956 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17957 | request.traffic_annotation = |
| 17958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17961 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17962 | MockWrite data_writes[] = { |
| 17963 | MockWrite("POST / HTTP/1.1\r\n" |
| 17964 | "Host: www.foo.com\r\n" |
| 17965 | "Connection: keep-alive\r\n" |
| 17966 | "Content-Length: 3\r\n\r\n"), |
| 17967 | MockWrite("foo"), |
| 17968 | }; |
| 17969 | |
| 17970 | MockRead data_reads[] = { |
| 17971 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17972 | MockRead(SYNCHRONOUS, OK), |
| 17973 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17974 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17975 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17976 | |
| 17977 | TestCompletionCallback callback; |
| 17978 | |
| 17979 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17980 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17981 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17982 | |
| 17983 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17984 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17985 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17986 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17987 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17988 | } |
| 17989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17990 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17991 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17992 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17993 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17994 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17995 | |
| 17996 | HttpRequestInfo request; |
| 17997 | request.method = "POST"; |
| 17998 | request.url = GURL("http://www.foo.com/"); |
| 17999 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18000 | request.traffic_annotation = |
| 18001 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18002 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18005 | MockWrite data_writes[] = { |
| 18006 | MockWrite("POST / HTTP/1.1\r\n" |
| 18007 | "Host: www.foo.com\r\n" |
| 18008 | "Connection: keep-alive\r\n" |
| 18009 | "Content-Length: 3\r\n\r\n"), |
| 18010 | MockWrite("foo"), |
| 18011 | }; |
| 18012 | |
| 18013 | MockRead data_reads[] = { |
| 18014 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18015 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18016 | MockRead(SYNCHRONOUS, OK), |
| 18017 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18018 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18020 | |
| 18021 | TestCompletionCallback callback; |
| 18022 | |
| 18023 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18024 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18025 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18026 | |
| 18027 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18028 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18030 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18031 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18032 | } |
| 18033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18034 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18035 | ChunkedUploadDataStream upload_data_stream(0); |
| 18036 | |
| 18037 | HttpRequestInfo request; |
| 18038 | request.method = "POST"; |
| 18039 | request.url = GURL("http://www.foo.com/"); |
| 18040 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18041 | request.traffic_annotation = |
| 18042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18046 | // Send headers successfully, but get an error while sending the body. |
| 18047 | MockWrite data_writes[] = { |
| 18048 | MockWrite("POST / HTTP/1.1\r\n" |
| 18049 | "Host: www.foo.com\r\n" |
| 18050 | "Connection: keep-alive\r\n" |
| 18051 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18052 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18053 | }; |
| 18054 | |
| 18055 | MockRead data_reads[] = { |
| 18056 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18057 | MockRead(SYNCHRONOUS, OK), |
| 18058 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18059 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18060 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18061 | |
| 18062 | TestCompletionCallback callback; |
| 18063 | |
| 18064 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18065 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18066 | |
| 18067 | base::RunLoop().RunUntilIdle(); |
| 18068 | upload_data_stream.AppendData("f", 1, false); |
| 18069 | |
| 18070 | base::RunLoop().RunUntilIdle(); |
| 18071 | upload_data_stream.AppendData("oo", 2, true); |
| 18072 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18073 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18074 | |
| 18075 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18076 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18077 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18078 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18079 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18080 | } |
| 18081 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18082 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18083 | const std::string& accept_encoding, |
| 18084 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18085 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18086 | bool should_match) { |
| 18087 | HttpRequestInfo request; |
| 18088 | request.method = "GET"; |
| 18089 | request.url = GURL("http://www.foo.com/"); |
| 18090 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18091 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18092 | request.traffic_annotation = |
| 18093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18094 | |
| 18095 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18096 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18097 | // Send headers successfully, but get an error while sending the body. |
| 18098 | MockWrite data_writes[] = { |
| 18099 | MockWrite("GET / HTTP/1.1\r\n" |
| 18100 | "Host: www.foo.com\r\n" |
| 18101 | "Connection: keep-alive\r\n" |
| 18102 | "Accept-Encoding: "), |
| 18103 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18104 | }; |
| 18105 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18106 | std::string response_code = "200 OK"; |
| 18107 | std::string extra; |
| 18108 | if (!location.empty()) { |
| 18109 | response_code = "301 Redirect\r\nLocation: "; |
| 18110 | response_code.append(location); |
| 18111 | } |
| 18112 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18113 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18114 | MockRead("HTTP/1.0 "), |
| 18115 | MockRead(response_code.data()), |
| 18116 | MockRead("\r\nContent-Encoding: "), |
| 18117 | MockRead(content_encoding.data()), |
| 18118 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18119 | MockRead(SYNCHRONOUS, OK), |
| 18120 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18121 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18122 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18123 | |
| 18124 | TestCompletionCallback callback; |
| 18125 | |
| 18126 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18128 | |
| 18129 | rv = callback.WaitForResult(); |
| 18130 | if (should_match) { |
| 18131 | EXPECT_THAT(rv, IsOk()); |
| 18132 | } else { |
| 18133 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18134 | } |
| 18135 | } |
| 18136 | |
| 18137 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18138 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18139 | } |
| 18140 | |
| 18141 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18142 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18143 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18144 | } |
| 18145 | |
| 18146 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18147 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18148 | "", false); |
| 18149 | } |
| 18150 | |
| 18151 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18152 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18153 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18154 | } |
| 18155 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18156 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18157 | ProxyConfig proxy_config; |
| 18158 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18159 | proxy_config.set_pac_mandatory(true); |
| 18160 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18161 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18162 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18163 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18164 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18165 | |
| 18166 | HttpRequestInfo request; |
| 18167 | request.method = "GET"; |
| 18168 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18169 | request.traffic_annotation = |
| 18170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18171 | |
| 18172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18174 | |
| 18175 | TestCompletionCallback callback; |
| 18176 | |
| 18177 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18179 | EXPECT_THAT(callback.WaitForResult(), |
| 18180 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18181 | } |
| 18182 | |
| 18183 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18184 | ProxyConfig proxy_config; |
| 18185 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18186 | proxy_config.set_pac_mandatory(true); |
| 18187 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18188 | new MockAsyncProxyResolverFactory(false); |
| 18189 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18190 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18191 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18192 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18193 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18194 | HttpRequestInfo request; |
| 18195 | request.method = "GET"; |
| 18196 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18197 | request.traffic_annotation = |
| 18198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18199 | |
| 18200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18202 | |
| 18203 | TestCompletionCallback callback; |
| 18204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18206 | |
| 18207 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18208 | ERR_FAILED, &resolver); |
| 18209 | EXPECT_THAT(callback.WaitForResult(), |
| 18210 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18211 | } |
| 18212 | |
| 18213 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18214 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18215 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18216 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18217 | session_deps_.enable_quic = false; |
| 18218 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18219 | |
| 18220 | HttpRequestInfo request; |
| 18221 | request.method = "GET"; |
| 18222 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18223 | request.traffic_annotation = |
| 18224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18225 | |
| 18226 | TestCompletionCallback callback; |
| 18227 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18230 | |
| 18231 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18232 | } |
| 18233 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18234 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18235 | // Reporting tests |
| 18236 | |
| 18237 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18238 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18239 | protected: |
| 18240 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18241 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18242 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18243 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18244 | test_reporting_context_ = test_reporting_context.get(); |
| 18245 | session_deps_.reporting_service = |
| 18246 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18247 | } |
| 18248 | |
| 18249 | TestReportingContext* reporting_context() const { |
| 18250 | return test_reporting_context_; |
| 18251 | } |
| 18252 | |
| 18253 | void clear_reporting_service() { |
| 18254 | session_deps_.reporting_service.reset(); |
| 18255 | test_reporting_context_ = nullptr; |
| 18256 | } |
| 18257 | |
| 18258 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18259 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18260 | HttpRequestInfo request; |
| 18261 | request.method = "GET"; |
| 18262 | request.url = GURL(url_); |
| 18263 | request.traffic_annotation = |
| 18264 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18265 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18266 | MockWrite data_writes[] = { |
| 18267 | MockWrite("GET / HTTP/1.1\r\n" |
| 18268 | "Host: www.example.org\r\n" |
| 18269 | "Connection: keep-alive\r\n\r\n"), |
| 18270 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18271 | MockRead data_reads[] = { |
| 18272 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18273 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18274 | "\"endpoints\": [{\"url\": " |
| 18275 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18276 | MockRead("\r\n"), |
| 18277 | MockRead("hello world"), |
| 18278 | MockRead(SYNCHRONOUS, OK), |
| 18279 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18280 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18281 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18282 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18283 | |
| 18284 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18285 | if (request.url.SchemeIsCryptographic()) { |
| 18286 | ssl.ssl_info.cert = |
| 18287 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18288 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18289 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18291 | } |
| 18292 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18293 | TestCompletionCallback callback; |
| 18294 | auto session = CreateSession(&session_deps_); |
| 18295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18297 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18298 | } |
| 18299 | |
| 18300 | protected: |
| 18301 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18302 | |
| 18303 | private: |
| 18304 | TestReportingContext* test_reporting_context_; |
| 18305 | }; |
| 18306 | |
| 18307 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18308 | DontProcessReportToHeaderNoService) { |
| 18309 | base::HistogramTester histograms; |
| 18310 | clear_reporting_service(); |
| 18311 | RequestPolicy(); |
| 18312 | histograms.ExpectBucketCount( |
| 18313 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18314 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18315 | } |
| 18316 | |
| 18317 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18318 | base::HistogramTester histograms; |
| 18319 | url_ = "http://www.example.org/"; |
| 18320 | RequestPolicy(); |
| 18321 | histograms.ExpectBucketCount( |
| 18322 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18323 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18324 | } |
| 18325 | |
| 18326 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18327 | RequestPolicy(); |
Lily Chen | efb6fcf | 2019-04-19 04:17:54 | [diff] [blame] | 18328 | ASSERT_EQ(1u, reporting_context()->cache()->GetEndpointCount()); |
| 18329 | const ReportingClient endpoint = |
| 18330 | reporting_context()->cache()->GetEndpointForTesting( |
| 18331 | url::Origin::Create(GURL("https://www.example.org/")), "nel", |
| 18332 | GURL("https://www.example.org/upload/")); |
| 18333 | EXPECT_TRUE(endpoint); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18334 | } |
| 18335 | |
| 18336 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18337 | DontProcessReportToHeaderInvalidHttps) { |
| 18338 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18339 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18340 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18341 | histograms.ExpectBucketCount( |
| 18342 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18343 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18344 | } |
| 18345 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18346 | |
| 18347 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18348 | // Network Error Logging tests |
| 18349 | |
| 18350 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18351 | namespace { |
| 18352 | |
| 18353 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18354 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18355 | |
| 18356 | } // namespace |
| 18357 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18358 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18359 | : public HttpNetworkTransactionTest { |
| 18360 | protected: |
| 18361 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18362 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18363 | auto network_error_logging_service = |
| 18364 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18365 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18366 | session_deps_.network_error_logging_service = |
| 18367 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18368 | |
| 18369 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18370 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18371 | |
| 18372 | request_.method = "GET"; |
| 18373 | request_.url = GURL(url_); |
| 18374 | request_.extra_headers = extra_headers_; |
| 18375 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18376 | request_.traffic_annotation = |
| 18377 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18378 | } |
| 18379 | |
| 18380 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18381 | return test_network_error_logging_service_; |
| 18382 | } |
| 18383 | |
| 18384 | void clear_network_error_logging_service() { |
| 18385 | session_deps_.network_error_logging_service.reset(); |
| 18386 | test_network_error_logging_service_ = nullptr; |
| 18387 | } |
| 18388 | |
| 18389 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18390 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18391 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18392 | MockWrite data_writes[] = { |
| 18393 | MockWrite("GET / HTTP/1.1\r\n" |
| 18394 | "Host: www.example.org\r\n" |
| 18395 | "Connection: keep-alive\r\n"), |
| 18396 | MockWrite(ASYNC, extra_header_string.data(), |
| 18397 | extra_header_string.size()), |
| 18398 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18399 | MockRead data_reads[] = { |
| 18400 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18401 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18402 | MockRead("\r\n"), |
| 18403 | MockRead("hello world"), |
| 18404 | MockRead(SYNCHRONOUS, OK), |
| 18405 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18406 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18407 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18408 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18409 | |
| 18410 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18411 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18412 | ssl.ssl_info.cert = |
| 18413 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18414 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18415 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18417 | } |
| 18418 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18419 | TestCompletionCallback callback; |
| 18420 | auto session = CreateSession(&session_deps_); |
| 18421 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18422 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18423 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18424 | |
| 18425 | std::string response_data; |
| 18426 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18427 | EXPECT_EQ("hello world", response_data); |
| 18428 | } |
| 18429 | |
| 18430 | void CheckReport(size_t index, |
| 18431 | int status_code, |
| 18432 | int error_type, |
| 18433 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18434 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18435 | |
| 18436 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18437 | network_error_logging_service()->errors()[index]; |
| 18438 | EXPECT_EQ(url_, error.uri); |
| 18439 | EXPECT_EQ(kReferrer, error.referrer); |
| 18440 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18441 | EXPECT_EQ(server_ip, error.server_ip); |
| 18442 | EXPECT_EQ("http/1.1", error.protocol); |
| 18443 | EXPECT_EQ("GET", error.method); |
| 18444 | EXPECT_EQ(status_code, error.status_code); |
| 18445 | EXPECT_EQ(error_type, error.type); |
| 18446 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18447 | } |
| 18448 | |
| 18449 | protected: |
| 18450 | std::string url_ = "https://www.example.org/"; |
| 18451 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18452 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18453 | HttpRequestHeaders extra_headers_; |
| 18454 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18455 | |
| 18456 | private: |
| 18457 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18458 | }; |
| 18459 | |
| 18460 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18461 | DontProcessNelHeaderNoService) { |
| 18462 | base::HistogramTester histograms; |
| 18463 | clear_network_error_logging_service(); |
| 18464 | RequestPolicy(); |
| 18465 | histograms.ExpectBucketCount( |
| 18466 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18467 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18468 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18469 | 1); |
| 18470 | } |
| 18471 | |
| 18472 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18473 | DontProcessNelHeaderHttp) { |
| 18474 | base::HistogramTester histograms; |
| 18475 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18476 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18477 | RequestPolicy(); |
| 18478 | histograms.ExpectBucketCount( |
| 18479 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18480 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18481 | } |
| 18482 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18483 | // Don't set NEL policies received on a proxied connection. |
| 18484 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18485 | DontProcessNelHeaderProxy) { |
| 18486 | session_deps_.proxy_resolution_service = |
| 18487 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18488 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18489 | BoundTestNetLog log; |
| 18490 | session_deps_.net_log = log.bound().net_log(); |
| 18491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18492 | |
| 18493 | HttpRequestInfo request; |
| 18494 | request.method = "GET"; |
| 18495 | request.url = GURL("https://www.example.org/"); |
| 18496 | request.traffic_annotation = |
| 18497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18498 | |
| 18499 | // Since we have proxy, should try to establish tunnel. |
| 18500 | MockWrite data_writes1[] = { |
| 18501 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18502 | "Host: www.example.org:443\r\n" |
| 18503 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18504 | |
| 18505 | MockWrite("GET / HTTP/1.1\r\n" |
| 18506 | "Host: www.example.org\r\n" |
| 18507 | "Connection: keep-alive\r\n\r\n"), |
| 18508 | }; |
| 18509 | |
| 18510 | MockRead data_reads1[] = { |
| 18511 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18512 | |
| 18513 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18514 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18515 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18516 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18517 | MockRead(SYNCHRONOUS, OK), |
| 18518 | }; |
| 18519 | |
| 18520 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18521 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18522 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18523 | ssl.ssl_info.cert = |
| 18524 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18525 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18526 | ssl.ssl_info.cert_status = 0; |
| 18527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18528 | |
| 18529 | TestCompletionCallback callback1; |
| 18530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18531 | |
| 18532 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18534 | |
| 18535 | rv = callback1.WaitForResult(); |
| 18536 | EXPECT_THAT(rv, IsOk()); |
| 18537 | |
| 18538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18539 | ASSERT_TRUE(response); |
| 18540 | EXPECT_EQ(200, response->headers->response_code()); |
| 18541 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18542 | |
| 18543 | // No NEL header was set. |
| 18544 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18545 | } |
| 18546 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18547 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18548 | RequestPolicy(); |
| 18549 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18550 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18551 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18552 | header.origin); |
| 18553 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18554 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18555 | } |
| 18556 | |
| 18557 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18558 | DontProcessNelHeaderInvalidHttps) { |
| 18559 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18560 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18561 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18562 | histograms.ExpectBucketCount( |
| 18563 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18564 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18565 | 1); |
| 18566 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18567 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18568 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18569 | RequestPolicy(); |
| 18570 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18571 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18572 | } |
| 18573 | |
| 18574 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18575 | CreateReportErrorAfterStart) { |
| 18576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18577 | auto trans = |
| 18578 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18579 | |
| 18580 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18581 | StaticSocketDataProvider data; |
| 18582 | data.set_connect_data(mock_connect); |
| 18583 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18584 | |
| 18585 | TestCompletionCallback callback; |
| 18586 | |
| 18587 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18588 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18589 | |
| 18590 | trans.reset(); |
| 18591 | |
| 18592 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18593 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18594 | IPAddress() /* server_ip */); |
| 18595 | } |
| 18596 | |
| 18597 | // Same as above except the error is ASYNC |
| 18598 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18599 | CreateReportErrorAfterStartAsync) { |
| 18600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18601 | auto trans = |
| 18602 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18603 | |
| 18604 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18605 | StaticSocketDataProvider data; |
| 18606 | data.set_connect_data(mock_connect); |
| 18607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18608 | |
| 18609 | TestCompletionCallback callback; |
| 18610 | |
| 18611 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18612 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18613 | |
| 18614 | trans.reset(); |
| 18615 | |
| 18616 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18617 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18618 | IPAddress() /* server_ip */); |
| 18619 | } |
| 18620 | |
| 18621 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18622 | CreateReportReadBodyError) { |
| 18623 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18624 | MockWrite data_writes[] = { |
| 18625 | MockWrite("GET / HTTP/1.1\r\n" |
| 18626 | "Host: www.example.org\r\n" |
| 18627 | "Connection: keep-alive\r\n"), |
| 18628 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18629 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18630 | MockRead data_reads[] = { |
| 18631 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18632 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18633 | MockRead("hello world"), |
| 18634 | MockRead(SYNCHRONOUS, OK), |
| 18635 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18636 | |
| 18637 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18638 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18639 | |
| 18640 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18641 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18642 | |
| 18643 | // Log start time |
| 18644 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18645 | |
| 18646 | TestCompletionCallback callback; |
| 18647 | auto session = CreateSession(&session_deps_); |
| 18648 | auto trans = |
| 18649 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18650 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18651 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18652 | |
| 18653 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18654 | ASSERT_TRUE(response); |
| 18655 | |
| 18656 | EXPECT_TRUE(response->headers); |
| 18657 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18658 | |
| 18659 | std::string response_data; |
| 18660 | rv = ReadTransaction(trans.get(), &response_data); |
| 18661 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18662 | |
| 18663 | trans.reset(); |
| 18664 | |
| 18665 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18666 | |
| 18667 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18668 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18669 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18670 | network_error_logging_service()->errors()[0]; |
| 18671 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18672 | } |
| 18673 | |
| 18674 | // Same as above except the final read is ASYNC. |
| 18675 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18676 | CreateReportReadBodyErrorAsync) { |
| 18677 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18678 | MockWrite data_writes[] = { |
| 18679 | MockWrite("GET / HTTP/1.1\r\n" |
| 18680 | "Host: www.example.org\r\n" |
| 18681 | "Connection: keep-alive\r\n"), |
| 18682 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18683 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18684 | MockRead data_reads[] = { |
| 18685 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18686 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18687 | MockRead("hello world"), |
| 18688 | MockRead(ASYNC, OK), |
| 18689 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18690 | |
| 18691 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18692 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18693 | |
| 18694 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18696 | |
| 18697 | // Log start time |
| 18698 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18699 | |
| 18700 | TestCompletionCallback callback; |
| 18701 | auto session = CreateSession(&session_deps_); |
| 18702 | auto trans = |
| 18703 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18704 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18705 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18706 | |
| 18707 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18708 | ASSERT_TRUE(response); |
| 18709 | |
| 18710 | EXPECT_TRUE(response->headers); |
| 18711 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18712 | |
| 18713 | std::string response_data; |
| 18714 | rv = ReadTransaction(trans.get(), &response_data); |
| 18715 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18716 | |
| 18717 | trans.reset(); |
| 18718 | |
| 18719 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18720 | |
| 18721 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18722 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18723 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18724 | network_error_logging_service()->errors()[0]; |
| 18725 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18726 | } |
| 18727 | |
| 18728 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18729 | CreateReportRestartWithAuth) { |
| 18730 | std::string extra_header_string = extra_headers_.ToString(); |
| 18731 | static const base::TimeDelta kSleepDuration = |
| 18732 | base::TimeDelta::FromMilliseconds(10); |
| 18733 | |
| 18734 | MockWrite data_writes1[] = { |
| 18735 | MockWrite("GET / HTTP/1.1\r\n" |
| 18736 | "Host: www.example.org\r\n" |
| 18737 | "Connection: keep-alive\r\n"), |
| 18738 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18739 | }; |
| 18740 | |
| 18741 | MockRead data_reads1[] = { |
| 18742 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18743 | // Give a couple authenticate options (only the middle one is actually |
| 18744 | // supported). |
| 18745 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18746 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18747 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18749 | // Large content-length -- won't matter, as connection will be reset. |
| 18750 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18751 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18752 | }; |
| 18753 | |
| 18754 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18755 | // be issuing -- the final header line contains the credentials. |
| 18756 | MockWrite data_writes2[] = { |
| 18757 | MockWrite("GET / HTTP/1.1\r\n" |
| 18758 | "Host: www.example.org\r\n" |
| 18759 | "Connection: keep-alive\r\n" |
| 18760 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18761 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18762 | }; |
| 18763 | |
| 18764 | // Lastly, the server responds with the actual content. |
| 18765 | MockRead data_reads2[] = { |
| 18766 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18767 | MockRead("hello world"), |
| 18768 | MockRead(SYNCHRONOUS, OK), |
| 18769 | }; |
| 18770 | |
| 18771 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18772 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18773 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18774 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18775 | |
| 18776 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18777 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18778 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18780 | |
| 18781 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18782 | base::TimeTicks restart_time; |
| 18783 | |
| 18784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18785 | auto trans = |
| 18786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18787 | |
| 18788 | TestCompletionCallback callback1; |
| 18789 | |
| 18790 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18791 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18792 | |
| 18793 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18794 | |
| 18795 | TestCompletionCallback callback2; |
| 18796 | |
| 18797 | // Wait 10 ms then restart with auth |
| 18798 | FastForwardBy(kSleepDuration); |
| 18799 | restart_time = base::TimeTicks::Now(); |
| 18800 | rv = |
| 18801 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18802 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18803 | |
| 18804 | std::string response_data; |
| 18805 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18806 | EXPECT_EQ("hello world", response_data); |
| 18807 | |
| 18808 | trans.reset(); |
| 18809 | |
| 18810 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18811 | // retry. Note that we don't report the error draining the body, as the first |
| 18812 | // request already generated a report for the auth challenge. |
| 18813 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18814 | |
| 18815 | // Check error report contents |
| 18816 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18817 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18818 | |
| 18819 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18820 | network_error_logging_service()->errors()[0]; |
| 18821 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18822 | network_error_logging_service()->errors()[1]; |
| 18823 | |
| 18824 | // Sanity-check elapsed time values |
| 18825 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18826 | // Check that the start time is refreshed when restarting with auth. |
| 18827 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18828 | } |
| 18829 | |
| 18830 | // Same as above, except draining the body before restarting fails |
| 18831 | // asynchronously. |
| 18832 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18833 | CreateReportRestartWithAuthAsync) { |
| 18834 | std::string extra_header_string = extra_headers_.ToString(); |
| 18835 | static const base::TimeDelta kSleepDuration = |
| 18836 | base::TimeDelta::FromMilliseconds(10); |
| 18837 | |
| 18838 | MockWrite data_writes1[] = { |
| 18839 | MockWrite("GET / HTTP/1.1\r\n" |
| 18840 | "Host: www.example.org\r\n" |
| 18841 | "Connection: keep-alive\r\n"), |
| 18842 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18843 | }; |
| 18844 | |
| 18845 | MockRead data_reads1[] = { |
| 18846 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18847 | // Give a couple authenticate options (only the middle one is actually |
| 18848 | // supported). |
| 18849 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18850 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18851 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18852 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18853 | // Large content-length -- won't matter, as connection will be reset. |
| 18854 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18855 | MockRead(ASYNC, ERR_FAILED), |
| 18856 | }; |
| 18857 | |
| 18858 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18859 | // be issuing -- the final header line contains the credentials. |
| 18860 | MockWrite data_writes2[] = { |
| 18861 | MockWrite("GET / HTTP/1.1\r\n" |
| 18862 | "Host: www.example.org\r\n" |
| 18863 | "Connection: keep-alive\r\n" |
| 18864 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18865 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18866 | }; |
| 18867 | |
| 18868 | // Lastly, the server responds with the actual content. |
| 18869 | MockRead data_reads2[] = { |
| 18870 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18871 | MockRead("hello world"), |
| 18872 | MockRead(SYNCHRONOUS, OK), |
| 18873 | }; |
| 18874 | |
| 18875 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18876 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18878 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18879 | |
| 18880 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18881 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18882 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18884 | |
| 18885 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18886 | base::TimeTicks restart_time; |
| 18887 | |
| 18888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18889 | auto trans = |
| 18890 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18891 | |
| 18892 | TestCompletionCallback callback1; |
| 18893 | |
| 18894 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18895 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18896 | |
| 18897 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18898 | |
| 18899 | TestCompletionCallback callback2; |
| 18900 | |
| 18901 | // Wait 10 ms then restart with auth |
| 18902 | FastForwardBy(kSleepDuration); |
| 18903 | restart_time = base::TimeTicks::Now(); |
| 18904 | rv = |
| 18905 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18906 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18907 | |
| 18908 | std::string response_data; |
| 18909 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18910 | EXPECT_EQ("hello world", response_data); |
| 18911 | |
| 18912 | trans.reset(); |
| 18913 | |
| 18914 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18915 | // retry. Note that we don't report the error draining the body, as the first |
| 18916 | // request already generated a report for the auth challenge. |
| 18917 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18918 | |
| 18919 | // Check error report contents |
| 18920 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18921 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18922 | |
| 18923 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18924 | network_error_logging_service()->errors()[0]; |
| 18925 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18926 | network_error_logging_service()->errors()[1]; |
| 18927 | |
| 18928 | // Sanity-check elapsed time values |
| 18929 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18930 | // Check that the start time is refreshed when restarting with auth. |
| 18931 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18932 | } |
| 18933 | |
| 18934 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18935 | CreateReportRetryKeepAliveConnectionReset) { |
| 18936 | std::string extra_header_string = extra_headers_.ToString(); |
| 18937 | MockWrite data_writes1[] = { |
| 18938 | MockWrite("GET / HTTP/1.1\r\n" |
| 18939 | "Host: www.example.org\r\n" |
| 18940 | "Connection: keep-alive\r\n"), |
| 18941 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18942 | MockWrite("GET / HTTP/1.1\r\n" |
| 18943 | "Host: www.example.org\r\n" |
| 18944 | "Connection: keep-alive\r\n"), |
| 18945 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18946 | }; |
| 18947 | |
| 18948 | MockRead data_reads1[] = { |
| 18949 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18950 | MockRead("hello"), |
| 18951 | // Connection is reset |
| 18952 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18953 | }; |
| 18954 | |
| 18955 | // Successful retry |
| 18956 | MockRead data_reads2[] = { |
| 18957 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18958 | MockRead("world"), |
| 18959 | MockRead(ASYNC, OK), |
| 18960 | }; |
| 18961 | |
| 18962 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18963 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18964 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18965 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18966 | |
| 18967 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18969 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18971 | |
| 18972 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18973 | auto trans1 = |
| 18974 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18975 | |
| 18976 | TestCompletionCallback callback1; |
| 18977 | |
| 18978 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18979 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18980 | |
| 18981 | std::string response_data; |
| 18982 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18983 | EXPECT_EQ("hello", response_data); |
| 18984 | |
| 18985 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18986 | |
| 18987 | auto trans2 = |
| 18988 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18989 | |
| 18990 | TestCompletionCallback callback2; |
| 18991 | |
| 18992 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18993 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18994 | |
| 18995 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18996 | EXPECT_EQ("world", response_data); |
| 18997 | |
| 18998 | trans1.reset(); |
| 18999 | trans2.reset(); |
| 19000 | |
| 19001 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19002 | // the second request, then an OK report from the successful retry. |
| 19003 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19004 | |
| 19005 | // Check error report contents |
| 19006 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19007 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19008 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19009 | } |
| 19010 | |
| 19011 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19012 | CreateReportRetryKeepAlive408) { |
| 19013 | std::string extra_header_string = extra_headers_.ToString(); |
| 19014 | MockWrite data_writes1[] = { |
| 19015 | MockWrite("GET / HTTP/1.1\r\n" |
| 19016 | "Host: www.example.org\r\n" |
| 19017 | "Connection: keep-alive\r\n"), |
| 19018 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19019 | MockWrite("GET / HTTP/1.1\r\n" |
| 19020 | "Host: www.example.org\r\n" |
| 19021 | "Connection: keep-alive\r\n"), |
| 19022 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19023 | }; |
| 19024 | |
| 19025 | MockRead data_reads1[] = { |
| 19026 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19027 | MockRead("hello"), |
| 19028 | // 408 Request Timeout |
| 19029 | MockRead(SYNCHRONOUS, |
| 19030 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19031 | "Connection: Keep-Alive\r\n" |
| 19032 | "Content-Length: 6\r\n\r\n" |
| 19033 | "Pickle"), |
| 19034 | }; |
| 19035 | |
| 19036 | // Successful retry |
| 19037 | MockRead data_reads2[] = { |
| 19038 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19039 | MockRead("world"), |
| 19040 | MockRead(ASYNC, OK), |
| 19041 | }; |
| 19042 | |
| 19043 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19044 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19045 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19046 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19047 | |
| 19048 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19049 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19050 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19052 | |
| 19053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19054 | auto trans1 = |
| 19055 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19056 | |
| 19057 | TestCompletionCallback callback1; |
| 19058 | |
| 19059 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19060 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19061 | |
| 19062 | std::string response_data; |
| 19063 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19064 | EXPECT_EQ("hello", response_data); |
| 19065 | |
| 19066 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19067 | |
| 19068 | auto trans2 = |
| 19069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19070 | |
| 19071 | TestCompletionCallback callback2; |
| 19072 | |
| 19073 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19074 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19075 | |
| 19076 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19077 | EXPECT_EQ("world", response_data); |
| 19078 | |
| 19079 | trans1.reset(); |
| 19080 | trans2.reset(); |
| 19081 | |
| 19082 | // One 200 report from first request, then a 408 report from |
| 19083 | // the second request, then a 200 report from the successful retry. |
| 19084 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19085 | |
| 19086 | // Check error report contents |
| 19087 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19088 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19089 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19090 | } |
| 19091 | |
| 19092 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19093 | CreateReportRetry421WithoutConnectionPooling) { |
| 19094 | // Two hosts resolve to the same IP address. |
| 19095 | const std::string ip_addr = "1.2.3.4"; |
| 19096 | IPAddress ip; |
| 19097 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19098 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19099 | |
| 19100 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19101 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19102 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19103 | |
| 19104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19105 | |
| 19106 | // Two requests on the first connection. |
| 19107 | spdy::SpdySerializedFrame req1( |
| 19108 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19109 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19110 | spdy::SpdySerializedFrame req2( |
| 19111 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19112 | spdy::SpdySerializedFrame rst( |
| 19113 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19114 | MockWrite writes1[] = { |
| 19115 | CreateMockWrite(req1, 0), |
| 19116 | CreateMockWrite(req2, 3), |
| 19117 | CreateMockWrite(rst, 6), |
| 19118 | }; |
| 19119 | |
| 19120 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19121 | spdy::SpdySerializedFrame resp1( |
| 19122 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19123 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19124 | spdy::SpdyHeaderBlock response_headers; |
| 19125 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19126 | spdy::SpdySerializedFrame resp2( |
| 19127 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19128 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19129 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19130 | |
| 19131 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19132 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19133 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19134 | |
| 19135 | AddSSLSocketData(); |
| 19136 | |
| 19137 | // Retry the second request on a second connection. |
| 19138 | SpdyTestUtil spdy_util2; |
| 19139 | spdy::SpdySerializedFrame req3( |
| 19140 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19141 | MockWrite writes2[] = { |
| 19142 | CreateMockWrite(req3, 0), |
| 19143 | }; |
| 19144 | |
| 19145 | spdy::SpdySerializedFrame resp3( |
| 19146 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19147 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19148 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19149 | MockRead(ASYNC, 0, 3)}; |
| 19150 | |
| 19151 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19152 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19153 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19154 | |
| 19155 | AddSSLSocketData(); |
| 19156 | |
| 19157 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19158 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19159 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19160 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19161 | |
| 19162 | HttpRequestInfo request1; |
| 19163 | request1.method = "GET"; |
| 19164 | request1.url = GURL("https://www.example.org/"); |
| 19165 | request1.load_flags = 0; |
| 19166 | request1.traffic_annotation = |
| 19167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19168 | auto trans1 = |
| 19169 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19170 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19171 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19172 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19173 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19174 | |
| 19175 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19176 | ASSERT_TRUE(response); |
| 19177 | ASSERT_TRUE(response->headers); |
| 19178 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19179 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19180 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19181 | std::string response_data; |
| 19182 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19183 | EXPECT_EQ("hello!", response_data); |
| 19184 | |
| 19185 | trans1.reset(); |
| 19186 | |
| 19187 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19188 | |
| 19189 | HttpRequestInfo request2; |
| 19190 | request2.method = "GET"; |
| 19191 | request2.url = GURL("https://mail.example.org/"); |
| 19192 | request2.load_flags = 0; |
| 19193 | request2.traffic_annotation = |
| 19194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19195 | auto trans2 = |
| 19196 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19197 | |
| 19198 | BoundTestNetLog log; |
| 19199 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19200 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19201 | |
| 19202 | response = trans2->GetResponseInfo(); |
| 19203 | ASSERT_TRUE(response); |
| 19204 | ASSERT_TRUE(response->headers); |
| 19205 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19206 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19207 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19208 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19209 | EXPECT_EQ("hello!", response_data); |
| 19210 | |
| 19211 | trans2.reset(); |
| 19212 | |
| 19213 | // One 200 report from the first request, then a 421 report from the |
| 19214 | // second request, then a 200 report from the successful retry. |
| 19215 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19216 | |
| 19217 | // Check error report contents |
| 19218 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19219 | network_error_logging_service()->errors()[0]; |
| 19220 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19221 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19222 | EXPECT_EQ("", error1.user_agent); |
| 19223 | EXPECT_EQ(ip, error1.server_ip); |
| 19224 | EXPECT_EQ("h2", error1.protocol); |
| 19225 | EXPECT_EQ("GET", error1.method); |
| 19226 | EXPECT_EQ(200, error1.status_code); |
| 19227 | EXPECT_EQ(OK, error1.type); |
| 19228 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19229 | |
| 19230 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19231 | network_error_logging_service()->errors()[1]; |
| 19232 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19233 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19234 | EXPECT_EQ("", error2.user_agent); |
| 19235 | EXPECT_EQ(ip, error2.server_ip); |
| 19236 | EXPECT_EQ("h2", error2.protocol); |
| 19237 | EXPECT_EQ("GET", error2.method); |
| 19238 | EXPECT_EQ(421, error2.status_code); |
| 19239 | EXPECT_EQ(OK, error2.type); |
| 19240 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19241 | |
| 19242 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19243 | network_error_logging_service()->errors()[2]; |
| 19244 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19245 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19246 | EXPECT_EQ("", error3.user_agent); |
| 19247 | EXPECT_EQ(ip, error3.server_ip); |
| 19248 | EXPECT_EQ("h2", error3.protocol); |
| 19249 | EXPECT_EQ("GET", error3.method); |
| 19250 | EXPECT_EQ(200, error3.status_code); |
| 19251 | EXPECT_EQ(OK, error3.type); |
| 19252 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19253 | } |
| 19254 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19255 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19256 | CreateReportCancelAfterStart) { |
| 19257 | StaticSocketDataProvider data; |
| 19258 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19259 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19260 | |
| 19261 | TestCompletionCallback callback; |
| 19262 | auto session = CreateSession(&session_deps_); |
| 19263 | auto trans = |
| 19264 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19265 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19266 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19267 | |
| 19268 | // Cancel after start. |
| 19269 | trans.reset(); |
| 19270 | |
| 19271 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19272 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19273 | IPAddress() /* server_ip */); |
| 19274 | } |
| 19275 | |
| 19276 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19277 | CreateReportCancelBeforeReadingBody) { |
| 19278 | std::string extra_header_string = extra_headers_.ToString(); |
| 19279 | MockWrite data_writes[] = { |
| 19280 | MockWrite("GET / HTTP/1.1\r\n" |
| 19281 | "Host: www.example.org\r\n" |
| 19282 | "Connection: keep-alive\r\n"), |
| 19283 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19284 | }; |
| 19285 | MockRead data_reads[] = { |
| 19286 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19287 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19288 | }; |
| 19289 | |
| 19290 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19291 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19292 | |
| 19293 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19294 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19295 | |
| 19296 | TestCompletionCallback callback; |
| 19297 | auto session = CreateSession(&session_deps_); |
| 19298 | auto trans = |
| 19299 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19300 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19302 | |
| 19303 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19304 | ASSERT_TRUE(response); |
| 19305 | |
| 19306 | EXPECT_TRUE(response->headers); |
| 19307 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19308 | |
| 19309 | // Cancel before reading the body. |
| 19310 | trans.reset(); |
| 19311 | |
| 19312 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19313 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19314 | } |
| 19315 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19316 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19317 | base::HistogramTester histograms; |
| 19318 | RequestPolicy(); |
| 19319 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19320 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19321 | |
| 19322 | // Make HTTP request |
| 19323 | std::string extra_header_string = extra_headers_.ToString(); |
| 19324 | MockRead data_reads[] = { |
| 19325 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19326 | MockRead("hello world"), |
| 19327 | MockRead(SYNCHRONOUS, OK), |
| 19328 | }; |
| 19329 | MockWrite data_writes[] = { |
| 19330 | MockWrite("GET / HTTP/1.1\r\n" |
| 19331 | "Host: www.example.org\r\n" |
| 19332 | "Connection: keep-alive\r\n"), |
| 19333 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19334 | }; |
| 19335 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19336 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19337 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19338 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19339 | // Insecure url |
| 19340 | url_ = "http://www.example.org/"; |
| 19341 | request_.url = GURL(url_); |
| 19342 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19343 | TestCompletionCallback callback; |
| 19344 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19345 | auto trans = |
| 19346 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19347 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19348 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19349 | |
| 19350 | std::string response_data; |
| 19351 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19352 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19353 | |
| 19354 | // Insecure request does not generate a report |
| 19355 | histograms.ExpectBucketCount( |
| 19356 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19357 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19358 | |
| 19359 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19360 | } |
| 19361 | |
| 19362 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19363 | DontCreateReportHttpError) { |
| 19364 | base::HistogramTester histograms; |
| 19365 | RequestPolicy(); |
| 19366 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19367 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19368 | |
| 19369 | // Make HTTP request that fails |
| 19370 | MockRead data_reads[] = { |
| 19371 | MockRead("hello world"), |
| 19372 | MockRead(SYNCHRONOUS, OK), |
| 19373 | }; |
| 19374 | |
| 19375 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19376 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19377 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19378 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19379 | request_.url = GURL(url_); |
| 19380 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19382 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19383 | auto trans = |
| 19384 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19385 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19386 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19387 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19388 | |
| 19389 | // Insecure request does not generate a report, regardless of existence of a |
| 19390 | // policy for the origin. |
| 19391 | histograms.ExpectBucketCount( |
| 19392 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19393 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19394 | |
| 19395 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19396 | } |
| 19397 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19398 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19399 | // proxy. |
| 19400 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19401 | HttpRequestInfo request; |
| 19402 | request.method = "GET"; |
| 19403 | request.url = GURL("https://www.example.org/"); |
| 19404 | request.traffic_annotation = |
| 19405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19406 | |
| 19407 | // Configure against proxy server "myproxy:70". |
| 19408 | session_deps_.proxy_resolution_service = |
| 19409 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19410 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19412 | |
| 19413 | // Since we have proxy, should try to establish tunnel. |
| 19414 | MockWrite data_writes1[] = { |
| 19415 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19416 | "Host: www.example.org:443\r\n" |
| 19417 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19418 | }; |
| 19419 | |
| 19420 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19421 | // connection. |
| 19422 | MockRead data_reads1[] = { |
| 19423 | // No credentials. |
| 19424 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19425 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19426 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19427 | }; |
| 19428 | |
| 19429 | MockWrite data_writes2[] = { |
| 19430 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19431 | // be issuing -- the final header line contains the credentials. |
| 19432 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19433 | "Host: www.example.org:443\r\n" |
| 19434 | "Proxy-Connection: keep-alive\r\n" |
| 19435 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19436 | |
| 19437 | MockWrite("GET / HTTP/1.1\r\n" |
| 19438 | "Host: www.example.org\r\n" |
| 19439 | "Connection: keep-alive\r\n\r\n"), |
| 19440 | }; |
| 19441 | |
| 19442 | MockRead data_reads2[] = { |
| 19443 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19444 | |
| 19445 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19446 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19447 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19448 | MockRead(SYNCHRONOUS, "hello"), |
| 19449 | }; |
| 19450 | |
| 19451 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19452 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19453 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19454 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19455 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19457 | |
| 19458 | TestCompletionCallback callback1; |
| 19459 | |
| 19460 | auto trans = |
| 19461 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19462 | |
| 19463 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19464 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19465 | |
| 19466 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19467 | EXPECT_EQ(407, response->headers->response_code()); |
| 19468 | |
| 19469 | std::string response_data; |
| 19470 | rv = ReadTransaction(trans.get(), &response_data); |
| 19471 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19472 | |
| 19473 | // No NEL report is generated for the 407. |
| 19474 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19475 | |
| 19476 | TestCompletionCallback callback2; |
| 19477 | |
| 19478 | rv = |
| 19479 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19480 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19481 | |
| 19482 | response = trans->GetResponseInfo(); |
| 19483 | EXPECT_EQ(200, response->headers->response_code()); |
| 19484 | |
| 19485 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19486 | EXPECT_EQ("hello", response_data); |
| 19487 | |
| 19488 | trans.reset(); |
| 19489 | |
| 19490 | // No NEL report is generated because we are behind a proxy. |
| 19491 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19492 | } |
| 19493 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19494 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19495 | ReportContainsUploadDepth) { |
| 19496 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19497 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19498 | RequestPolicy(); |
| 19499 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19500 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19501 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19502 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19503 | } |
| 19504 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19505 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19506 | std::string extra_header_string = extra_headers_.ToString(); |
| 19507 | static const base::TimeDelta kSleepDuration = |
| 19508 | base::TimeDelta::FromMilliseconds(10); |
| 19509 | |
| 19510 | std::vector<MockWrite> data_writes = { |
| 19511 | MockWrite(ASYNC, 0, |
| 19512 | "GET / HTTP/1.1\r\n" |
| 19513 | "Host: www.example.org\r\n" |
| 19514 | "Connection: keep-alive\r\n"), |
| 19515 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19516 | }; |
| 19517 | |
| 19518 | std::vector<MockRead> data_reads = { |
| 19519 | // Write one byte of the status line, followed by a pause. |
| 19520 | MockRead(ASYNC, 2, "H"), |
| 19521 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19522 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19523 | MockRead(ASYNC, 5, "hello world"), |
| 19524 | MockRead(SYNCHRONOUS, OK, 6), |
| 19525 | }; |
| 19526 | |
| 19527 | SequencedSocketData data(data_reads, data_writes); |
| 19528 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19529 | |
| 19530 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19532 | |
| 19533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19534 | |
| 19535 | auto trans = |
| 19536 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19537 | |
| 19538 | TestCompletionCallback callback; |
| 19539 | |
| 19540 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19542 | |
| 19543 | data.RunUntilPaused(); |
| 19544 | ASSERT_TRUE(data.IsPaused()); |
| 19545 | FastForwardBy(kSleepDuration); |
| 19546 | data.Resume(); |
| 19547 | |
| 19548 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19549 | |
| 19550 | std::string response_data; |
| 19551 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19552 | EXPECT_EQ("hello world", response_data); |
| 19553 | |
| 19554 | trans.reset(); |
| 19555 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19556 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19557 | |
| 19558 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19559 | |
| 19560 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19561 | network_error_logging_service()->errors()[0]; |
| 19562 | |
| 19563 | // Sanity-check elapsed time in error report |
| 19564 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19565 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19566 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19567 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19568 | |
Batalov Vladislav | a4e97a50 | 2019-04-11 15:35:23 | [diff] [blame] | 19569 | TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) { |
| 19570 | HttpRequestInfo request; |
| 19571 | request.method = "GET"; |
| 19572 | request.url = GURL("http://example.org/"); |
| 19573 | |
| 19574 | request.load_flags = LOAD_ONLY_FROM_CACHE; |
| 19575 | |
| 19576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19577 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 19578 | TestCompletionCallback callback1; |
| 19579 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 19580 | |
| 19581 | EXPECT_THAT(rv, IsError(ERR_CACHE_MISS)); |
| 19582 | } |
| 19583 | |
Steven Valdez | 1c185917 | 2019-04-10 15:33:28 | [diff] [blame] | 19584 | TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) { |
| 19585 | HttpRequestInfo request; |
| 19586 | request.method = "GET"; |
| 19587 | request.url = GURL("https://www.example.org/"); |
| 19588 | request.traffic_annotation = |
| 19589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19590 | |
| 19591 | MockWrite data_writes[] = { |
| 19592 | MockWrite("GET / HTTP/1.1\r\n" |
| 19593 | "Host: www.example.org\r\n" |
| 19594 | "Connection: keep-alive\r\n\r\n"), |
| 19595 | }; |
| 19596 | |
| 19597 | // The proxy responds to the connect with a 407, using a persistent |
| 19598 | // connection. |
| 19599 | MockRead data_reads[] = { |
| 19600 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19601 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19602 | MockRead(SYNCHRONOUS, "1"), |
| 19603 | }; |
| 19604 | |
| 19605 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19607 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19608 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19609 | session_deps_.enable_early_data = true; |
| 19610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19611 | |
| 19612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19613 | |
| 19614 | TestCompletionCallback callback; |
| 19615 | auto trans = |
| 19616 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19617 | |
| 19618 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19620 | |
| 19621 | rv = callback.WaitForResult(); |
| 19622 | EXPECT_THAT(rv, IsOk()); |
| 19623 | |
| 19624 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19625 | ASSERT_TRUE(response); |
| 19626 | ASSERT_TRUE(response->headers); |
| 19627 | EXPECT_EQ(200, response->headers->response_code()); |
| 19628 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19629 | |
| 19630 | // Check that ConfirmHandshake wasn't called. |
| 19631 | ASSERT_FALSE(ssl.ConfirmDataConsumed()); |
| 19632 | ASSERT_TRUE(ssl.WriteBeforeConfirm()); |
| 19633 | |
| 19634 | trans.reset(); |
| 19635 | |
| 19636 | session->CloseAllConnections(); |
| 19637 | } |
| 19638 | |
| 19639 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmSyncWrite) { |
| 19640 | HttpRequestInfo request; |
| 19641 | request.method = "POST"; |
| 19642 | request.url = GURL("https://www.example.org/"); |
| 19643 | request.traffic_annotation = |
| 19644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19645 | |
| 19646 | MockWrite data_writes[] = { |
| 19647 | MockWrite(SYNCHRONOUS, |
| 19648 | "POST / HTTP/1.1\r\n" |
| 19649 | "Host: www.example.org\r\n" |
| 19650 | "Connection: keep-alive\r\n" |
| 19651 | "Content-Length: 0\r\n\r\n"), |
| 19652 | }; |
| 19653 | |
| 19654 | // The proxy responds to the connect with a 407, using a persistent |
| 19655 | // connection. |
| 19656 | MockRead data_reads[] = { |
| 19657 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19658 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19659 | MockRead(SYNCHRONOUS, "1"), |
| 19660 | }; |
| 19661 | |
| 19662 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19663 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19664 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19665 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19666 | session_deps_.enable_early_data = true; |
| 19667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19668 | |
| 19669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19670 | |
| 19671 | TestCompletionCallback callback; |
| 19672 | auto trans = |
| 19673 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19674 | |
| 19675 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19677 | |
| 19678 | rv = callback.WaitForResult(); |
| 19679 | EXPECT_THAT(rv, IsOk()); |
| 19680 | |
| 19681 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19682 | ASSERT_TRUE(response); |
| 19683 | ASSERT_TRUE(response->headers); |
| 19684 | EXPECT_EQ(200, response->headers->response_code()); |
| 19685 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19686 | |
| 19687 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19688 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19689 | |
| 19690 | trans.reset(); |
| 19691 | |
| 19692 | session->CloseAllConnections(); |
| 19693 | } |
| 19694 | |
| 19695 | TEST_F(HttpNetworkTransactionTest, ZeroRTTSyncConfirmAsyncWrite) { |
| 19696 | HttpRequestInfo request; |
| 19697 | request.method = "POST"; |
| 19698 | request.url = GURL("https://www.example.org/"); |
| 19699 | request.traffic_annotation = |
| 19700 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19701 | |
| 19702 | MockWrite data_writes[] = { |
| 19703 | MockWrite(ASYNC, |
| 19704 | "POST / HTTP/1.1\r\n" |
| 19705 | "Host: www.example.org\r\n" |
| 19706 | "Connection: keep-alive\r\n" |
| 19707 | "Content-Length: 0\r\n\r\n"), |
| 19708 | }; |
| 19709 | |
| 19710 | // The proxy responds to the connect with a 407, using a persistent |
| 19711 | // connection. |
| 19712 | MockRead data_reads[] = { |
| 19713 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19714 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19715 | MockRead(SYNCHRONOUS, "1"), |
| 19716 | }; |
| 19717 | |
| 19718 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19720 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19721 | ssl.confirm = MockConfirm(SYNCHRONOUS, OK); |
| 19722 | session_deps_.enable_early_data = true; |
| 19723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19724 | |
| 19725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19726 | |
| 19727 | TestCompletionCallback callback; |
| 19728 | auto trans = |
| 19729 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19730 | |
| 19731 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19733 | |
| 19734 | rv = callback.WaitForResult(); |
| 19735 | EXPECT_THAT(rv, IsOk()); |
| 19736 | |
| 19737 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19738 | ASSERT_TRUE(response); |
| 19739 | ASSERT_TRUE(response->headers); |
| 19740 | EXPECT_EQ(200, response->headers->response_code()); |
| 19741 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19742 | |
| 19743 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19744 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19745 | |
| 19746 | trans.reset(); |
| 19747 | |
| 19748 | session->CloseAllConnections(); |
| 19749 | } |
| 19750 | |
| 19751 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmSyncWrite) { |
| 19752 | HttpRequestInfo request; |
| 19753 | request.method = "POST"; |
| 19754 | request.url = GURL("https://www.example.org/"); |
| 19755 | request.traffic_annotation = |
| 19756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19757 | |
| 19758 | MockWrite data_writes[] = { |
| 19759 | MockWrite(SYNCHRONOUS, |
| 19760 | "POST / HTTP/1.1\r\n" |
| 19761 | "Host: www.example.org\r\n" |
| 19762 | "Connection: keep-alive\r\n" |
| 19763 | "Content-Length: 0\r\n\r\n"), |
| 19764 | }; |
| 19765 | |
| 19766 | // The proxy responds to the connect with a 407, using a persistent |
| 19767 | // connection. |
| 19768 | MockRead data_reads[] = { |
| 19769 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19770 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19771 | MockRead(SYNCHRONOUS, "1"), |
| 19772 | }; |
| 19773 | |
| 19774 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19776 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19777 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19778 | session_deps_.enable_early_data = true; |
| 19779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19780 | |
| 19781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19782 | |
| 19783 | TestCompletionCallback callback; |
| 19784 | auto trans = |
| 19785 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19786 | |
| 19787 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19789 | |
| 19790 | rv = callback.WaitForResult(); |
| 19791 | EXPECT_THAT(rv, IsOk()); |
| 19792 | |
| 19793 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19794 | ASSERT_TRUE(response); |
| 19795 | ASSERT_TRUE(response->headers); |
| 19796 | EXPECT_EQ(200, response->headers->response_code()); |
| 19797 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19798 | |
| 19799 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19800 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19801 | |
| 19802 | trans.reset(); |
| 19803 | |
| 19804 | session->CloseAllConnections(); |
| 19805 | } |
| 19806 | |
| 19807 | TEST_F(HttpNetworkTransactionTest, ZeroRTTAsyncConfirmAsyncWrite) { |
| 19808 | HttpRequestInfo request; |
| 19809 | request.method = "POST"; |
| 19810 | request.url = GURL("https://www.example.org/"); |
| 19811 | request.traffic_annotation = |
| 19812 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19813 | |
| 19814 | MockWrite data_writes[] = { |
| 19815 | MockWrite(ASYNC, |
| 19816 | "POST / HTTP/1.1\r\n" |
| 19817 | "Host: www.example.org\r\n" |
| 19818 | "Connection: keep-alive\r\n" |
| 19819 | "Content-Length: 0\r\n\r\n"), |
| 19820 | }; |
| 19821 | |
| 19822 | // The proxy responds to the connect with a 407, using a persistent |
| 19823 | // connection. |
| 19824 | MockRead data_reads[] = { |
| 19825 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19826 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19827 | MockRead(SYNCHRONOUS, "1"), |
| 19828 | }; |
| 19829 | |
| 19830 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19831 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19832 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19833 | ssl.confirm = MockConfirm(ASYNC, OK); |
| 19834 | session_deps_.enable_early_data = true; |
| 19835 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19836 | |
| 19837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19838 | |
| 19839 | TestCompletionCallback callback; |
| 19840 | auto trans = |
| 19841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19842 | |
| 19843 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19845 | |
| 19846 | rv = callback.WaitForResult(); |
| 19847 | EXPECT_THAT(rv, IsOk()); |
| 19848 | |
| 19849 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19850 | ASSERT_TRUE(response); |
| 19851 | ASSERT_TRUE(response->headers); |
| 19852 | EXPECT_EQ(200, response->headers->response_code()); |
| 19853 | EXPECT_EQ(1, response->headers->GetContentLength()); |
| 19854 | |
| 19855 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19856 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19857 | |
| 19858 | trans.reset(); |
| 19859 | |
| 19860 | session->CloseAllConnections(); |
| 19861 | } |
| 19862 | |
| 19863 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorSync) { |
| 19864 | HttpRequestInfo request; |
| 19865 | request.method = "POST"; |
| 19866 | request.url = GURL("https://www.example.org/"); |
| 19867 | request.traffic_annotation = |
| 19868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19869 | |
| 19870 | MockWrite data_writes[] = { |
| 19871 | MockWrite("POST / HTTP/1.1\r\n" |
| 19872 | "Host: www.example.org\r\n" |
| 19873 | "Connection: keep-alive\r\n" |
| 19874 | "Content-Length: 0\r\n\r\n"), |
| 19875 | }; |
| 19876 | |
| 19877 | // The proxy responds to the connect with a 407, using a persistent |
| 19878 | // connection. |
| 19879 | MockRead data_reads[] = { |
| 19880 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19881 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19882 | MockRead(SYNCHRONOUS, "1"), |
| 19883 | }; |
| 19884 | |
| 19885 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19887 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19888 | ssl.confirm = MockConfirm(SYNCHRONOUS, ERR_SSL_PROTOCOL_ERROR); |
| 19889 | session_deps_.enable_early_data = true; |
| 19890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19891 | |
| 19892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19893 | |
| 19894 | TestCompletionCallback callback; |
| 19895 | auto trans = |
| 19896 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19897 | |
| 19898 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19900 | |
| 19901 | rv = callback.WaitForResult(); |
| 19902 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19903 | |
| 19904 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19905 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19906 | |
| 19907 | trans.reset(); |
| 19908 | |
| 19909 | session->CloseAllConnections(); |
| 19910 | } |
| 19911 | |
| 19912 | TEST_F(HttpNetworkTransactionTest, ZeroRTTConfirmErrorAsync) { |
| 19913 | HttpRequestInfo request; |
| 19914 | request.method = "POST"; |
| 19915 | request.url = GURL("https://www.example.org/"); |
| 19916 | request.traffic_annotation = |
| 19917 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19918 | |
| 19919 | MockWrite data_writes[] = { |
| 19920 | MockWrite("POST / HTTP/1.1\r\n" |
| 19921 | "Host: www.example.org\r\n" |
| 19922 | "Connection: keep-alive\r\n" |
| 19923 | "Content-Length: 0\r\n\r\n"), |
| 19924 | }; |
| 19925 | |
| 19926 | // The proxy responds to the connect with a 407, using a persistent |
| 19927 | // connection. |
| 19928 | MockRead data_reads[] = { |
| 19929 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19930 | MockRead("Content-Length: 1\r\n\r\n"), |
| 19931 | MockRead(SYNCHRONOUS, "1"), |
| 19932 | }; |
| 19933 | |
| 19934 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19936 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 19937 | ssl.confirm = MockConfirm(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 19938 | session_deps_.enable_early_data = true; |
| 19939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19940 | |
| 19941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19942 | |
| 19943 | TestCompletionCallback callback; |
| 19944 | auto trans = |
| 19945 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19946 | |
| 19947 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 19948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19949 | |
| 19950 | rv = callback.WaitForResult(); |
| 19951 | EXPECT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
| 19952 | |
| 19953 | // Check that the Write didn't get called before ConfirmHandshake completed. |
| 19954 | ASSERT_FALSE(ssl.WriteBeforeConfirm()); |
| 19955 | |
| 19956 | trans.reset(); |
| 19957 | |
| 19958 | session->CloseAllConnections(); |
| 19959 | } |
| 19960 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19961 | } // namespace net |